Hi everybody,
I had almost the same problem some weeks ago. I read an article saying that HABTM is making some trouble from time to time and that it might be a better solution to split the HABTM relationship into a belongsTo and hasMany relationship. I changed my model User and UsersGroup and added for each model a BT and HM relationship - and it worked. I just had to call $this->Membership->find(...);
Maybe this approach is working for you, too.
and this: http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany-through
Hope it helps.
Greetings
Am Donnerstag, 5. Juli 2012 11:58:05 UTC+2 schrieb JonStark:
Strangely, this works ace in the controller :--public function countFollowing($id) {
$following = $this->User->UsersUser->find('count', array(
'conditions' => array(
'follower_id' => $id
),
));
return($following);
}But then in the model, the code below returns find function on a non object... what am I doing wrong? :public function countFollowing($id) {
$following = $this->UsersUser->find('count', array(
'conditions' => array(
'follower_id' => $id
),
));
return($following);
}
Le mercredi 4 juillet 2012 20:38:05 UTC+2, JonStark a écrit :Hi everyone !I have a question that shouldn't be that hard but I really can't manage it :In my app, User HABTM Userusers_users table is : id, following_id, follower_idI want to count every user where follower id is $id.This is my function :public function countFollowing($id) {
$user = $this->User->find('all', array(
'conditions' => array(
'UserUsers.follower_id' => $id
),
));
count($user);
}But it returns Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'UserUsers.follower_id' in 'where clause'... Any idea why ? Thanks a lot for your time !
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
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
No comments:
Post a Comment