Should i use belongsTo or hasOne in Laravel?

后端 未结 3 1413
深忆病人
深忆病人 2020-12-12 12:51

Consider two models A and B

A -> relatedTo B is a one to one relationship

What is the differ

3条回答
  •  执念已碎
    2020-12-12 13:40

    No, the difference depends on where your foreign key is.

    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.

提交回复
热议问题