Hi Sarah,
If you have a reasonably complicated find query with associated models
and conditions, the core 'Containable' behaviour is very handy:
http://book.cakephp.org/view/474/Containable
so in your AppModel put this (and all your models will have access to
the behaviour):
var $actsAs = array('Containable');
then you would have for your query something like this:
$array = $this->User->find('all',array(
    'fields'=>array('id','animal_id'),
    'order'=>array('id'=>'asc'),
    'contain'=>array(
         Animal=>array(
            fields=>array('frontfilename')
         ),
         Userpage=>array(
            'conditions'=>array(
                'approved' => '1'
            ),
            'order'=>array(
                'id'=>'desc')
         )
    )
));
Note that conditions, fields and order options are all specified on a
per-model basis  - you get back only what you want from each model.
Containable is definitely worth the effort to learn.

cheers,
C.

On Aug 29, 7:40 am, Sarah <sarah.e.p.jo...@gmail.com> wrote:
> I fixed my syntax,
>
> $conditions = array('or' => array( 'Userpage.approved' => 1, 'User.id'
> => $id) );
> $order = array('User.id ASC', 'Userpage.id DESC');
> $array = $this->User->find('all', array('fields'=>array('id',
> 'Userpage.id', 'User.animal_id', 'Animal.frontfilename'),
> 'conditions'=>$conditions, 'order'=>$order));
>
>  but I'm still getting the same errors as before.
>
> I verified that a User has many userpage and that a userpage belongs
> to a user.
> The SELECTing of the Animal picture is not a problem...I don't
> understand why it won't SELECT the userpage information...
>
> My recursive level is set to 1, I tried setting it to 2, but it didn't
> make a difference.
>
> Thanks for your time and help,
> ~Sarah
>
> On Aug 28, 12:23 pm, WebbedIT <p...@webbedit.co.uk> wrote:
>
> > Looks like you very nearly had it.  Just got your find syntax slightly
> > wrong, try:
>
> > $array = $this->User->find('all', array(
> >   'fields'=>array('id, 'Userpage.id', 'User.animal_id',
> > 'Animal.frontfilename'),
> >   'conditions'=>$conditions,
> >   'order'=>$order
> > );
>
> > Then go have a look at the cookbook and study the syntax of the find
> > command a bit more.  The first parameter should be the type of call,
> > in this instance 'all'.
>
> > The second parameter needs to be an array with your fields,
> > conditions, order etc.
>
> > Hope this helps
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to