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
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
Then you should only need to do:
return $this->Following->find('count');
That's if the method is in your model. If in the controller,
$this->User->Following ...
On Wed, Jul 4, 2012 at 5:43 PM, JonStark wrote:
> My User Model :
>
>> class User extends AppModel {
>> public $name = 'User';
>>
My User Model :
class User extends AppModel {
> public $name = 'User';
>
> public $hasAndBelongsToMany = array(
> 'Following' => array(
> 'className' => 'User',
> 'joinTable' => 'users_users',
> 'foreignKey' => 'follower_id',
> 'associatio
No wait -- that won't work.
Which table has the follower_id column? And what do your associations look like?
On Wed, Jul 4, 2012 at 5:32 PM, lowpass wrote:
> Is your User model associated with UserUsers? You said that User HABTM
> User. What is the alias you're using for that? UserUsers?
>
> And
Is your User model associated with UserUsers? You said that User HABTM
User. What is the alias you're using for that? UserUsers?
And is this function in the controller or model? If model, then
$this->UserUsers->find()
On Wed, Jul 4, 2012 at 5:12 PM, JonStark wrote:
> Thanks for the advice, but w
Thanks for the advice, but when I tried this, it returned :
Call to a member function find() on a non-object
for this code :
public function countFollowing($id) {
> $user = $this->User->UserUsers->find('all', array(
> 'conditions' => array(
> 'follower_id' => $id
> ),
> ));
> debug($user);
>
Because your User table has no such column. Try running the find on
the associated model.
$this->User->UserUsers->find(...)
On Wed, Jul 4, 2012 at 2:38 PM, JonStark wrote:
> Hi everyone !
>
> I have a question that shouldn't be that hard but I really can't manage it :
>
> In my app, User HABTM
Hi everyone !
I have a question that shouldn't be that hard but I really can't manage it :
In my app, User HABTM User
users_users table is : id, following_id, follower_id
I want to count every user where follower id is $id.
This is my function :
public function countFollowing($id) {
> $user =