trait CanBeOneOfMany

Properties

protected bool $isOneOfMany

Determines whether the relationship is one-of-many.

protected string $relationName

The name of the relationship.

protected Builder<mixed>|null $oneOfManySubQuery

The one of many inner join subselect query builder instance.

Methods

void
addOneOfManySubQueryConstraints(Builder $query, string|null $column = null, string|null $aggregate = null)

Add constraints for inner join subselect for one of many relationships.

array|string
getOneOfManySubQuerySelectColumns()

Get the columns the determine the relationship groups.

void
addOneOfManyJoinSubQueryConstraints(JoinClause $join)

Add join query constraints for one of many relationships.

ofMany(string|array|null $column = 'id', string|Closure|null $aggregate = 'MAX', string|null $relation = null)

Indicate that the relation is a single result of a larger one-to-many relationship.

latestOfMany(string|array|null $column = 'id', string|null $relation = null)

Indicate that the relation is the latest single result of a larger one-to-many relationship.

oldestOfMany(string|array|null $column = 'id', string|null $relation = null)

Indicate that the relation is the oldest single result of a larger one-to-many relationship.

string
getDefaultOneOfManyJoinAlias(string $relation)

Get the default alias for the one of many inner join clause.

newOneOfManySubQuery(string|array $groupBy, array|null $columns = null, string|null $aggregate = null)

Get a new query for the related model, grouping the query by the given column, often the foreign key of the relationship.

void
addOneOfManyJoinSubQuery(Builder $parent, Builder $subQuery, array $on)

Add the join subquery to the given query on the given column and the relationship's foreign key.

void
mergeOneOfManyJoinsTo(Builder $query)

Merge the relationship query joins to the given query builder.

getRelationQuery()

Get the query builder that will contain the relationship constraints.

Builder|null
getOneOfManySubQuery()

Get the one of many inner join subselect builder instance.

string
qualifySubSelectColumn(string $column)

Get the qualified column name for the one-of-many relationship using the subselect join query's alias.

string
qualifyRelatedColumn(string $column)

Qualify related column using the related table name if it is not already qualified.

string
guessRelationship()

Guess the "hasOne" relationship's name via backtrace.

bool
isOneOfMany()

Determine whether the relationship is a one-of-many relationship.

string
getRelationName()

Get the name of the relationship.

Details

at line 38
abstract void addOneOfManySubQueryConstraints(Builder $query, string|null $column = null, string|null $aggregate = null)

Add constraints for inner join subselect for one of many relationships.

Parameters

Builder $query
string|null $column
string|null $aggregate

Return Value

void

at line 43
abstract array|string getOneOfManySubQuerySelectColumns()

Get the columns the determine the relationship groups.

Return Value

array|string

at line 48
abstract void addOneOfManyJoinSubQueryConstraints(JoinClause $join)

Add join query constraints for one of many relationships.

Parameters

JoinClause $join

Return Value

void

at line 57
CanBeOneOfMany ofMany(string|array|null $column = 'id', string|Closure|null $aggregate = 'MAX', string|null $relation = null)

Indicate that the relation is a single result of a larger one-to-many relationship.

Parameters

string|array|null $column
string|Closure|null $aggregate
string|null $relation

Return Value

CanBeOneOfMany

Exceptions

InvalidArgumentException

at line 137
CanBeOneOfMany latestOfMany(string|array|null $column = 'id', string|null $relation = null)

Indicate that the relation is the latest single result of a larger one-to-many relationship.

Parameters

string|array|null $column
string|null $relation

Return Value

CanBeOneOfMany

at line 149
CanBeOneOfMany oldestOfMany(string|array|null $column = 'id', string|null $relation = null)

Indicate that the relation is the oldest single result of a larger one-to-many relationship.

Parameters

string|array|null $column
string|null $relation

Return Value

CanBeOneOfMany

at line 159
protected string getDefaultOneOfManyJoinAlias(string $relation)

Get the default alias for the one of many inner join clause.

Parameters

string $relation

Return Value

string

at line 172
protected Builder newOneOfManySubQuery(string|array $groupBy, array|null $columns = null, string|null $aggregate = null)

Get a new query for the related model, grouping the query by the given column, often the foreign key of the relationship.

Parameters

string|array $groupBy
array|null $columns
string|null $aggregate

Return Value

Builder

at line 208
protected void addOneOfManyJoinSubQuery(Builder $parent, Builder $subQuery, array $on)

Add the join subquery to the given query on the given column and the relationship's foreign key.

Parameters

Builder $parent
Builder $subQuery
array $on

Return Value

void

at line 228
protected void mergeOneOfManyJoinsTo(Builder $query)

Merge the relationship query joins to the given query builder.

Parameters

Builder $query

Return Value

void

at line 240
protected Builder getRelationQuery()

Get the query builder that will contain the relationship constraints.

Return Value

Builder

at line 252
Builder|null getOneOfManySubQuery()

Get the one of many inner join subselect builder instance.

Return Value

Builder|null

at line 260
string qualifySubSelectColumn(string $column)

Get the qualified column name for the one-of-many relationship using the subselect join query's alias.

Parameters

string $column

Return Value

string

at line 268
protected string qualifyRelatedColumn(string $column)

Qualify related column using the related table name if it is not already qualified.

Parameters

string $column

Return Value

string

at line 276
protected string guessRelationship()

Guess the "hasOne" relationship's name via backtrace.

Return Value

string

at line 284
bool isOneOfMany()

Determine whether the relationship is a one-of-many relationship.

Return Value

bool

at line 292
string getRelationName()

Get the name of the relationship.

Return Value

string