I know you can define in the model what fields should be retrieved when
making a find. Maybe you can also add conditions.


On Sat, May 22, 2010 at 6:24 AM, shantamg <[email protected]> wrote:

> Every model in my app has a foreign key called "schedule_id". I need
> to narrow my finds so that they only return data with the schedule_id
> that is in the session. The long and annoying way to do it this is:
>
>        function show($id) {
>                $this->Person->id = $id;
>                $schedule_id = $this->Session->read('Schedule.id');
>                $this->Person->contain(
>                        "Hobby.schedule_id = {$schedule_id}",
>                        "Job.schedule_id = {$schedule_id}"
>                );
>                $data = $this->Person->find('first', array(
>                        'conditions' => array(
>                                'Person.schedule_id' => $schedule_id
>                        )
>                ));
>
>                etc...
>
>        }
>
> Is there a way to do something in the beforeFilter of the
> appController (bindModel maybe?) that checks the session for the
> schedule id and sets up the conditions so that all I have to do in the
> controller action is something like this?:
>
>        function show($id) {
>                $this->Person->id = $id;
>                $this->Person->contain('Hobby', 'Job');
>                $data = $this->Person->find('first');
>
>                etc...
>
>        }
>
> Thanks for your help!
> Jason
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> 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]<cake-php%[email protected]>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to