Friday, August 28, 2009

Re: Using belongsTo and hasMany relationships: Is it possible to access tables through a chain of relationships?

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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: