Hi, i have two user_id’s in a table called ‘Peoples’ and i want to output the data of the second one that is not declared as ‘user_id’ but as ‘user2id’
both tables are already linked by the user_id. i want to access the data of another user and i want to identify him by the ‘user2id’ because there is already an object with user_id… best would be if i can add the user2id to this object with a leftjoin…
It sounds like you have two fields in your Peoples table which are both IDs that index into your Users table, but for different purposes? For example, maybe one is the user’s profile and the other is the user’s manager or something like that. In which case you would need a second association, as I said (though I guess on the Peoples table, not Users), and then you’d contain ['Profiles', 'Managers'] or whatever.
If that’s not your scenario, I think you may need to show some database schema and table associations, because this isn’t clear. You’ve referenced “user2id” but also “frequestid”, for example.
it is a request for friendship. the user_id came from the users object after been added to the peoples table and it is the id in the users table (primarykey). the peopleid is the id of the user that i want to add to the friendlist or who i want to approve.
i want to show the name of the user behind the ‘peopleid’ but i cant use it because i dont know how…
" echo $user->$people-> peopleid ->$profile->$name "
should be something like that…
the user object should be extended by the user behind the peopleid
Okay, so the structure is actually that users can “have and belong to” many users, as a friend relation, and the peoples table is the join table for this structure?
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘Users.user_id’ in ‘on clause’
the peopleid of the friends table should become equal to the user_id of the peoples table… in my scenario it should also be ‘hasOne’ not ‘BelongsTo’ … every peopleid has only one user
how can i define a association of an address table of which the friends table ‘hasOne’ by the way?
SELECT Users.id AS Users__id, Users.email AS Users__email, Users.password AS Users__password, Users.role AS Users__role, Users.image AS Users__image, Users.created AS Users__created, Users.modified AS Users__modified, Friends.id AS Friends__id, Friends.email AS Friends__email, Friends.password AS Friends__password, Friends.role AS Friends__role, Friends.image AS Friends__image, Friends.created AS Friends__created, Friends.modified AS Friends__modified FROM users Users LEFT JOIN users Friends ON Friends.id = (Users.user_id) WHERE Users.id = :c0 LIMIT 1
Well, I did say it was untested. Just 'foreign_key' => 'id', it would seem.
It’s a belongsToMany relation because people can have many friends, and be the friend of many people. Don’t think about the relation to the join table in cases like that; that’s almost always something you can ignore entirely.
In your case, you want the relation to be called Friends, not Categories. You want those friends to be Users, not Categories. You want the join table to be peoples, not articles_categories. And foreignKey and targetForeignKey should be the fields from the join table, you should be able to see which one relates to the record that you’re finding associated record for (article_id in my case, should be user_id in yours, right?) and which relates to the records in the associated table (category_id in my case, peopleid in yours).
not… i used your code now and there was no error but there is still the same issue… he did not create a user that is based on the peopleid…
friend is just the same user as declared in the peoples table no exchange between the ids…
if I use ‘className’ => ‘Users’ he is using the table Users instead of the table peoples so everything is wrong…
SELECT Peoples.id AS Friends_CJoin__id, Peoples.user_id AS Friends_CJoin__user_id, Peoples.frequestid AS Friends_CJoin__frequestid, Friends.id AS Friends__id, Friends.email AS Friends__email, Friends.created AS Friends__created, Friends.modified AS Friends__modified FROM users Friends INNER JOIN Peoples Peoples ON Friends.id = (Peoples.user_id) WHERE Peoples.user_id in (8)
if i use ‘className’ => ‘Peoples’ i get the correct table…
SELECT Peoples.id AS Friends_CJoin__id, Peoples.user_id AS Friends_CJoin__user_id, Peoples.frequestid AS Friends_CJoin__frequestid, Friends.id AS Friends__id, Friends.user_id AS Friends__user_id, Friends.frequestid AS Friends__frequestid FROM Peoples Friends INNER JOIN Peoples Peoples ON Friends.id = (Peoples.peopleid) WHERE Peoples.user_id in (8)
but this is still not the solution because i need the information of the user behind the peopleid…
like this he only provides the information of regular user_id