MorphTo class final
morphTo: the inverse of MorphOne / MorphMany. Each row names its
owner's type in morphType and key in foreignKey, so rows of one
table may point at different models (a comment on a post or a video).
morphName defaults to the name the relation is registered under, as
Laravel defaults it to the method name. Stored types are resolved
through types and then Relation.morphMap: there is no reflection to
turn App\Models\Post into a model, so every possible target must be
listed in one of the two.
Constructors
Properties
- foreignKey → String
-
The column holding the owner's key (
{morphName}_id).no setter - hashCode → int
-
The hash code for this object.
no setterinherited
-
knownTypes
→ List<
ModelDefinition< Model> > -
Every model this relation may point at: types, then the morph map.
no setter
-
matchColumns
→ List<
String> -
The related rows' columns this relation matches them on (its foreign
or owner key): added back when an eager load selects columns without
them (
with_('user:name')still readsusers.id).no setterinherited - morphName → String
-
no setter
- morphType → String
-
The column holding the owner's morph class (
{morphName}_type).no setter - name ↔ String
-
Name under which the relation is registered (set by the definition).
getter/setter pairinherited
- ownerKey → String?
-
The key of the target models (their primary key when null).
final
-
parentColumns
→ List<
String> -
The parent rows' columns this relation reads (its local or foreign
key): added to a parent query that selects columns without them, so
the relation can still be loaded from its rows.
no setteroverride
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
types
→ List<
ModelDefinition< Model> Function()> -
The models this relation may point at (besides Relation.morphMap).
final
Methods
-
associate(
Model child, Model owner) → void -
Points
childatowner(no save). -
Not available: the owner table depends on each row.
whereHason aMorphTogoes throughwhereHasMorphinstead.override -
A query on
typecorrelated with the parent table (namedparentTable), forwhereHasMorph. -
definitionFor(
String type) → ModelDefinition< Model> -
The model stored as
typein morphType: its alias or, as Laravel still resolves rows written before an alias existed, its class name. -
dissociate(
Model child) → void -
Clears the morph columns of
child(no save). -
eagerLoad(
List< Model> parents, DatabaseManager db, [RelationConstraint? constraint]) → Future<void> -
One query per stored type, as Laravel's
MorphToeager loads.override -
existenceQuery(
ModelDefinition< Model> parent, DatabaseManager db, {required String parentTable}) → ModelQuery<Model> -
correlated against the parent table as
parentTablenames it (an alias inside a self-relation subquery). The built-in relations alias their own table when it has the parent's name (categorieswhosechildrenarecategories); custom relations fall back to correlated.inherited -
loadedModels(
List< Model> parents) → List<Model> -
The models loaded under name on
parents, flattened (for nested eager loading).inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
queryFor(
Model parent, DatabaseManager db) → ModelQuery< Model> -
Query returning the related models of one
parent.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited