当前位置:网站首页>Differences between belongsto and hasone

Differences between belongsto and hasone

2022-06-09 08:10:00 xcbzsy

hasOne Positive correlation ,belongsTo Reverse correlation .
In short, it's , No big difference , It's just a deviation in logic ( Logical rationality ).
belongsTo: It can be understood as belonging to
hasOne: It can be understood as having

First , We create two tables .
user surface Field id name password Field
user_address surface id user_id city Field
It's not hard to see. ,user_address Is based on user Extended tables . We can say ,user Have user_address The foreign key ,user_address Foreign key for user.

User Association in the model user_address When using tables hasOne
UserAddress Association in the model user When using tables belongsTo

You can understand :
I (User) Have (hasOne) A it (user_address), I (user_address) Belong to (belongsTo) it (User).

原网站

版权声明
本文为[xcbzsy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090805324810.html

随机推荐