hasOne relationship with pivot table #3782
Unanswered
MiguelFreire
asked this question in
Help
Replies: 2 comments 3 replies
-
@MiguelFreire Hello! Why do you want to create a pivot table for a 'hasOne' relationship? Pivot tables are meant to be used with "manyToMany" relationships. Take a look at the hasOne docs. |
Beta Was this translation helpful? Give feedback.
3 replies
-
There are a couple of ways around it.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Let's suppose I have the following database schema:
How can I create an hasOne relationship with a pivot table?
I could solve this by adding a nullable foreign key column to users, but I don't really like that. So I was thinking of using an intermediate model (UserAvatar) to represent the pivot table (users_avatars) and set a belongsTo to the other two models, and in the User and Avatar model create a hasOne to UserAvatar model.
Any suggestions/ideas?
Ty
Beta Was this translation helpful? Give feedback.
All reactions