abstract class Relation (View source)

Properties

static protected bool $has_constraints

Indicates whether the relation is adding constraints.

static protected bool $has_pivot

Indicate whether the relationships use a pivot table.*.

protected string $foreign_key

The foreign key of the parent model.

protected string $primary_key

The associated key on the parent model.

protected Model $parent

The parent model instance

$related

The related model instance

protected QueryBuilder $query

The Bow Query builder

protected bool $eager_has_no_keys

Whether no parent exposed a key during eager loading, in which case the relation resolves to nothing without querying the database.

Methods

__construct(Model $related, Model $parent)

Relation Contractor

void
addConstraints()

Set the base constraints on the relation query.

mixed
getResults()

Get the results of the relationship.

string
eagerParentKey()

The parent attribute whose value is matched against the related models.

string
eagerRelatedKey()

The related column queried when eager loading the relation.

bool
eagerIsMany()

Whether the relation resolves to many related models.

getParent()

Get the parent model.

getRelated()

Get associated model class.

create(array $attributes)

Create a new row of the related

static mixed
noConstraints(Closure $callback)

Run the given callback with relation constraints disabled.

void
addEagerConstraints(array $parents)

Constrain the relation query to every parent key in a single whereIn.

getEager()

Execute the eager query and return the related models.

void
match(array $parents, Collection $results, string $name)

Match the eager loaded related models back onto their parents.

mixed
__call(string $method, array $args = [])

_Call

Details

__construct(Model $related, Model $parent)

Relation Contractor

Parameters

Model $related
Model $parent

abstract void addConstraints()

Set the base constraints on the relation query.

Return Value

void

abstract mixed getResults()

Get the results of the relationship.

Return Value

mixed

abstract protected string eagerParentKey()

The parent attribute whose value is matched against the related models.

Return Value

string

abstract protected string eagerRelatedKey()

The related column queried when eager loading the relation.

Return Value

string

abstract protected bool eagerIsMany()

Whether the relation resolves to many related models.

Return Value

bool

Model getParent()

Get the parent model.

Return Value

Model

Model getRelated()

Get associated model class.

Return Value

Model

Model create(array $attributes)

Create a new row of the related

Parameters

array $attributes

Return Value

Model

static mixed noConstraints(Closure $callback)

Run the given callback with relation constraints disabled.

Lets the eager loader build a relation without the single parent WHERE clause so it can be replaced by a batched whereIn over every parent.

Parameters

Closure $callback

Return Value

mixed

void addEagerConstraints(array $parents)

Constrain the relation query to every parent key in a single whereIn.

Parameters

array $parents

Return Value

void

Collection getEager()

Execute the eager query and return the related models.

Return Value

Collection

void match(array $parents, Collection $results, string $name)

Match the eager loaded related models back onto their parents.

Parameters

array $parents
Collection $results
string $name

Return Value

void

mixed __call(string $method, array $args = [])

_Call

Parameters

string $method
array $args

Return Value

mixed