Re: Ingherited models that filter active users/records?
Or, if there is a connection between Users and People, set up a new association in the User model - say, ActivePerson - and set a condition on it:
var $hasMany = array(
'ActivePerson' => array(
'className' => 'Person',
'conditions' => array(
'ActivePerson.active' => 1
)
)
);
Then make all your finds against the User model instead of the Person model:
$people = $this->User->ActivePerson->find('all');
Might not be quite as clean, but it' works well.
On 20 Jul 2012, at 21:01, Mike Griffin wrote:
> On Fri, Jul 20, 2012 at 5:44 PM, geste <jim.hogan@gmail.com> wrote:
>> However, I find myself writing a lot of snippets in controllers that
>> essentially go "WHERE active = '1'" and that seems like it could be a pain
>> and error-prone over time.
>>
>> What I'd like to do is leave "People" alone but create a new model or model
>> called "Users" that simply flters People for active=1. And maybe a
>> corresponding model that is OldUsers and feteches active=0.
>>
>> I started to implement something like this at the controller level but then
>> asked myself why not implement at Model level. Does this seems liek a
>> rational approach. Can anyone point to some good examples outside of basic
>> API docs?
>
> The model is the perfect place to put this. Have a look at creating
> custom find types
> (http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#creating-custom-find-types)
>
> You can set whatever filters you want in there.
>
> Mike.
>
> --
> Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home