Thinkphp5 difference model of belongsTo and hasOne

belongsTo and hasOne have said one relationship

Foreign key table associated primary key table using the associated primary key table using the foreign key table belongsTo hasOne

For example:

First, there is the user table field id name password field
and then have user_address table id user_id city field

HasOne used in the model when the associated User user_address table, because no two tables in the user table associated with the foreign key

Use belongsTo, in UserAddress model when the associated user table as a foreign key user_id has two tables in the associated table user_address

Guess you like

Origin www.cnblogs.com/hulewa/p/11857865.html