The model who's table contains the foreign key will have belongsTo() in it while the model who's table contains that primary key to which that foreign key is referencing to will have hasOne()... its easy the model that has the foreign key will have belongsTo() and the one that doesn't contain the foreign Key in that relationship will have hasOne(). and no they are not interchangeable using the wrong method will always return null as a result.
"BelongsTo" goes in the table with the "xxx_id" column.
例如:
国家有城市。
City 属于 Country (City 表中的 Country _ id)。
另一个例子:
一张脸只有一个鼻子。
鼻子属于一张脸(鼻子表中的 face _ id)。