Last Updated: 2022-12-01
The only difference between
belongsTo is where the foreign key
column is located.
Let's say you have two entities: User and an Account.
If the users table has the
account_id column then a User
Account. (And the Account either
But if the users table does not have the
account_id column, and instead
the accounts table has the
user_id column, then User
belongsTo are inverses of one another - if one record
belongTo the other, the other
hasOne of the first. Or, more accurately,
hasMany - depending on how many times its id appears.