Issue in relationship #539
-
HI sorry a wired bug in relationship or may be its me i am scratching my head from last 2 days but didnt get around it. please see the code but the result which i get from index function just one record relationship recorded. can you please tell me what i am doing wrong i see the repo keys etc all are okay. userfriends has a relation in contact model @binaryk can you please check it |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 13 replies
-
I'd recommend you use the same key in the Repository as the name of the function in your User model.
|
Beta Was this translation helpful? Give feedback.
-
@arthurkirkosa i am doing same please see the snippets Table structure is users have user id as uuid
Key on contacts repository is
API call if is like that
Result i am expecting is all friend_ids with relation but now i am getting error of un defined function maps
Please guide am i doing something wrong |
Beta Was this translation helpful? Give feedback.
-
Also if i use belongsTo relation like that it will only return first record as relation output something like that Please guide as it just show relation for first record |
Beta Was this translation helpful? Give feedback.
-
Yes, as Contact has a BelongTo with User, that's the relation you have to use in your ContactRepository as well. Because a Contact Belongs To a User, it's normal for you to have just one item of User loaded with that Contact If you what the full list of contacts start from the User repo For clarity I would rename the methods in each model to the corresponding entity
Naming them in singular and plural would outline how many object I should receive when using the relation in the code |
Beta Was this translation helpful? Give feedback.
-
@wasiqaftab I moved this issue to a Discussion. |
Beta Was this translation helpful? Give feedback.
-
@arthurkirkosa i have same issue |
Beta Was this translation helpful? Give feedback.
-
When you log in with the current user... it has many contacts, which have a single relation to another User... and you need to see the currently logged in user's friends (Contact->User) The architecture that you want is a User has many friends (User) and each User can befriend other users. If so, you need a ManyToMany relationship between users and don't need that Contact model. |
Beta Was this translation helpful? Give feedback.
Yes, as Contact has a BelongTo with User, that's the relation you have to use in your ContactRepository as well.
Because a Contact Belongs To a User, it's normal for you to have just one item of User loaded with that Contact
If you what the full list of contacts start from the User repo
GET /api/restify/users?related=userfriends
For clarity I would rename the methods in each model to the corresponding entity
Naming them in singular and plural would outline how many object I should receive when using the …