考虑两个型号A
和B
A
-> relatedTo B
is a one to one
relationship
What is the difference in using (A ->hasOne
-- B) and (A ->belongsTo
-- B)?
Can I use them interchangeably?
考虑两个型号A
和B
A
-> relatedTo B
is a one to one
relationship
What is the difference in using (A ->hasOne
-- B) and (A ->belongsTo
-- B)?
Can I use them interchangeably?
不,区别取决于外键的位置.
In your example, if A
has a b_id
column, then A
belongsTo
B
.
If B
has an a_id
column, then A
hasOne
or hasMany
B
depending on how many B
should have.