Yup. Bindable would easily trim those sql down easily to just what you need.
But most of the things bindable does is already available in the core of
cakephp using containable. Refer to cakebakers notes on it at
http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/. Makes
cutting sql down much easier.
On Sat, Jun 7, 2008 at 8:19 AM, Ken <[EMAIL PROTECTED]> wrote:
>
> OK... after working on this for a day or so I post the message and
> then five minutes later stumble onto the right answer. For my case, I
> used:
>
> $this->Course->User->findByUsername(...);
>
> This returned an array that included courses for the particular user.
> It also came back with other HABTM associations for the user, and I
> would love to trim the SQL down in an ideal world, but this is a big
> step for now.
>
> Ken
>
> On Jun 6, 7:11 pm, Ken <[EMAIL PROTECTED]> wrote:
> > Just started developing with CakePHP a few weeks ago. Loved it until I
> > ran into this seemingly simple problem that is proving difficult to
> > navigate. Using CakePHP 1.2 Nightly from 6 Jun 2008:
> >
> > I have a standard HABTM relationship. In this case it is Courses and
> > Users. A course can have many users (students), and a user (student)
> > can have many courses. When the user logs in, I would like to restrict
> > the courses view to only courses associated with that particular user.
> > Seem like a simple question? I can't make it work.
> >
> > Here is my best shot so far:
> >
> > $conditions = array('User.username' => $this->Session->read('User'));
> > $courselist = $this->Course->find('all',array('conditions' =>
> > $conditions,
> > 'recursive' => 5));
> >
> > I kept playing with the recursive number, but based on the SQL I'm
> > seeing I simply can't get the course model to retrieve data from the
> > user model. I verified using scaffolding that the associations are
> > properly established.
> >
> > Ken
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---