Difference between has one belongs to and has many

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the databases category.

Last Updated: 2022-12-01

The only difference between hasOne and belongsTo is where the foreign key column is located.

Let's say you have two entities: User and an Account.

In short hasOne and belongsTo are inverses of one another - if one record belongTo the other, the other hasOne of the first. Or, more accurately, eiterh hasOne or hasMany - depending on how many times its id appears.