Re: Access Data in Associations Efficiently

2011-11-30 Thread phpMagpie
@Andras: That's an awful lot of work, @ Jordy: I recommend you learn how to use Containable which makes the task as simple as: $this->User->find('first', array( 'conditions'=>array('User.id'=>$uid), 'contain'=>array('Pet'=>'Post') )); Simple and efficient! HTH, Paul. http://book.cakephp.

Re: Access Data in Associations Efficiently

2011-11-29 Thread Andras Kende
Jordy, You could do something like: 1. get all pets .id of a user $userPets = $this->User->Pet->find('all', array( 'fields' => array('Pet.user_id'), 'conditions' => array( 'Pet.user_id' => $uid ), )); $petIds = Set::combine($userPets, '{n}.Pet.id'); $pos

Re: Access Data in Associations Efficiently

2011-11-29 Thread euromark
especially as beginner you should ALWAYS bake your code first using the bake shell "cake bake ..." it will produce out of the box code you can already use to create/edit/ view/delete records step two then is "adjusting" the baked code to your needs the advantage: you can easily modify your relati

Access Data in Associations Efficiently

2011-11-29 Thread Jordy van Kuijk
Hi all, I've managed to set up most of my associations and models in CakePHP (I'm a noobie). Now I have a very basic question. Let me explain the situation first. I have got a User, Pet and Post model. The user hasmany pets, the pet hasmany posts. The user can also log in. Now in my controller,