Relation<R extends Model> class
abstract
Base relation (BLUEPRINT_V2 §7.5.4). Related definitions are resolved lazily through a thunk so two models may reference each other.
- Implementers
Constructors
- Relation()
-
A relation to the model of the definition
_relatedreturns, read lazily so mutually referencing models can be declared.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
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 setter - name ↔ String
-
Name under which the relation is registered (set by the definition).
getter/setter pair
-
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 setter
-
parentDefinition
↔ ModelDefinition<
Model> ? -
The definition the relation is declared on (set by the definition);
it names the default foreign key of HasMany and HasOne.
getter/setter pair
-
The related model's definition.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
A query on the related table correlated with the parent table, for
whereHas/withCount. -
eagerLoad(
List< Model> parents, DatabaseManager db, [RelationConstraint? constraint]) → Future<void> -
Loads the relation for many
parentsin one batched query and stores the result on each parent under name. -
existenceQuery(
ModelDefinition< Model> parent, DatabaseManager db, {required String parentTable}) → ModelQuery<R> -
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. -
loadedModels(
List< Model> parents) → List<Model> -
The models loaded under name on
parents, flattened (for nested eager loading). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
queryFor(
Model parent, DatabaseManager db) → ModelQuery< R> -
Query returning the related models of one
parent. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- requiresMorphMap → bool
-
Whether models without a morph alias are refused (requireMorphMap).
no setter
Static Methods
-
chunk<
T> (List< T> items, int size) → List<List< T> > -
Splits
itemsinto lists of at mostsize, to keepINlists within the database's limits. -
enforceMorphMap(
Map< String, ModelDefinition< map, {bool merge = true}) → voidModel> Function()> - morphMap and requireMorphMap: every model used in a polymorphic relation must then have an alias.
-
keepColumns(
QueryBuilder query, String table, Iterable< Object> columns) → void -
Adds the
columnsthatquery(ontable) does not select yet; bare names are qualified withtable. A query that selects every column (none listed,*,table.*) is left alone. -
morphClassOf(
ModelDefinition< Model> definition) → String -
The value stored in
*_typecolumns fordefinition(Laravel'sgetMorphClass): its morph alias, else its ModelDefinition.morphClass. -
morphedModel(
String alias) → ModelDefinition< Model> ? -
The definition registered under
alias(getMorphedModel), or null. -
morphMap(
[Map< String, ModelDefinition< ? map, bool merge = true]) → Map<Model> Function()>String, ModelDefinition< Model> Function()> -
Registers morph aliases: a model listed here is stored in
*_typecolumns under its alias ('post') instead of its ModelDefinition.morphClass, and MorphTo resolves the alias back. Returns the current map. -
qualifySelect(
QueryBuilder query, String table) → void -
Qualifies the bare column names
queryselects withtable: a query joining a pivot or intermediate table would findidambiguous. -
requireMorphMap(
[bool require = true]) → void -
Whether models without a morph alias are refused
(
ClassMorphViolationExceptionin Laravel).