Hi James, You're absolutely right. I can't agree more on the fat model idea.
Your approach should definitely work, but I still need to dive into controllers and make changes to find calls. And what's more, what about the paginate things? What about containable queries that concern this model... I assume there should be a way to globally set this condition in the scope of this particular model? Like setting conditions to Model.approved = 1, which affects all queries, paginations as well as containable. Something like this one, but much simpler: http://bakery.cakephp.org/articles/view/soft-delete-behavior As for the admin part, maybe I can disable this condition on the fly before whenever a query is made. On Jul 29, 2:13 pm, JamesF <[email protected]> wrote: > "It's an existing site, so I don't want to rewrite conditions for all > find queries. " > > ahh thats why we should be using fat models instead of fat > controllers. > > the most direct way to achieve this would be to put it in each find > call. > > the best way would be to set up a function in your model, lets call it > findApproved() > > so in you model you put > > function findApproved(){ > > $data = $this->find('all', array('conditions'=>array > ('Model.approved'=>1, > more conditions etc etc))); > > return $data; > > } > > in your controller just put > $this->Model->findApproved() in place of those old rusty controller > find calls. > > On Jul 29, 1:38 am, park <[email protected]> wrote: > > > > > Hi, > > > Would like to add an "approved" field for a model. Users can only see > > entries whose Model.approved = 1. Only in admin section can unapproved > > entries be retrieved. > > > It's an existing site, so I don't want to rewrite conditions for all > > find queries. > > > Is there a centralized method (presumably in Model) of achieving this? > > > Many thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
