polymorphicBelongsTorelationship is a
many-to-onerelationship. This relationship is used when an entity can belong to multiple types of entities. The classic example for this type of relationship is
Comments. For instance, a
Commentmay belong to a
prefixfor the polymorphic type. A common convention where is to add
ableto the end of the entity name, though this is not automatically done. In our example, this prefix is
commentable. This tells quick to look for a
commentable_idcolumn in our
Commententity. It stores our entity's mapping as the
_typeand our entity's primary key value as the
_idis used to retrieve a
_typefrom the database.
polymorphicHasMany. It is important to choose the right relationship for your database structure.
hasOneassumes that the related model has the foreign key for the relationship.
name & "_type"
name & "_id"
realtedentity that is referred to by the