Announcement

Collapse
No announcement yet.

Difference between link type "belongsTo" and "belongsToParent"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference between link type "belongsTo" and "belongsToParent"

    Could someone explain what are the main differences or consequences when choosing between these two types of links ?. Thanks in advance.

  • #2
    Found my answer a while ago but wanted to share it here because I just don't like unanswered/ignored questions :-).

    In "belongsTo" an entity can have one type of parent, for example a branch always belongs to a tree, thus the branch table would have a column named tree_id and it would be called using ORM as $branch->get('treeId')

    In "belongsToParent" an entity can have more than one types of parent, for example son->favoriteFamilyMember where the favorite family member can be a brother, a sister, an uncle, a cousin, etc and there are entities for each type of family member, thus the son table would contain two columns to reflect this relationship, one column named parent_id and a second column named parent_type. To get these values in ORM you would use $son->get('favoriteFamilyMemberId') and $son->get('favoriteFamilyMemberTypeType')

    Comment

    Working...
    X