HasMany
class HasMany extends HasOneOrMany
Has many relation.
Constants
EAGER_LOAD_CHUNK_SIZE |
Eager load chunk size. |
Properties
protected Connection | $connection | Database connection. | from Query |
protected HelperInterface | $helper | Query helper. | from Query |
protected Compiler | $compiler | Query compiler. | from Query |
protected mixed | $table | Database table. | from Query |
protected bool | $distinct | Select distinct? | from Query |
protected array | $setOperations | Set operations. | from Query |
protected array | $columns | Columns from which we are fetching data. | from Query |
protected array | $wheres | WHERE clauses. | from Query |
protected array | $joins | JOIN clauses. | from Query |
protected array | $groupings | GROUP BY clauses. | from Query |
protected array | $havings | HAVING clauses. | from Query |
protected array | $orderings | ORDER BY clauses. | from Query |
protected int|null | $limit | Limit. | from Query |
protected int|null | $offset | Offset. | from Query |
protected bool|string|null | $lock | Lock. | from Query |
protected string|null | $prefix | Prefix. | from Query |
protected bool | $inSubqueryContext | Is the query in subquery context? | from Query |
static protected PaginationFactoryInterface | $paginationFactory | Pagination factory. | from Query |
protected ORM | $model | Instance of the model to hydrate. | from Query |
protected ORM | $parent | Parent record. | from Relation |
protected string | $foreignKey | Foreign key. | from Relation |
protected bool | $lazy | Lazy load related records? | from Relation |
Methods
Constructor.
Adds a WHERE clause.
Adds a raw WHERE clause.
Adds a OR WHERE clause.
Adds a raw OR WHERE clause.
Adds a BETWEEN clause.
Adds a NOT BETWEEN clause.
Adds a OR NOT BETWEEN clause.
Adds a IN clause.
Adds a IS NULL clause.
Adds a JOIN clause.
Adds a raw JOIN clause.
Adds a LEFT OUTER JOIN clause.
Adds a raw LEFT OUTER JOIN clause.
Adds a HAVING clause.
Adds a raw HAVING clause.
Adds a raw OR HAVING clause.
Executes a SELECT query and returns the value of the chosen column of the first row of the result set.
Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.
Executes a SELECT query and returns an array where the first column is used as keys and the second as values.
Executes a SELECT query and returns the first row of the result set.
Executes a SELECT query and returns an array containing all of the result set rows.
Executes a SELECT query and returns a generator that lets you iterate over the results.
Fetches data in batches and passes them to the processor closure.
Sets the selected column of the query to the chosen aggreate.
Returns the number of distinct values of the chosen column.
Inserts data into the chosen table and returns the auto increment id.
Sets the criterion used when eager loading related records.
Returns a related result set from the database.
Details
in Relation at line 63
__construct(Connection $connection, ORM $parent, ORM $related, string $foreignKey = null)
Constructor.
in Query at line 169
__clone()
Create a fresh compiler instance when we clone the query.
in Query at line 201
static
setPaginationFactory(PaginationFactoryInterface|Closure $factory)
Sets the pagination factory.
in Query at line 211
static PaginationFactoryInterface
getPaginationFactory()
Gets the pagination factory.
in Query at line 228
Connection
getConnection()
Returns the connection instance.
in Query at line 248
array
getSetOperations()
Returns the set operations.
in Query at line 258
mixed
getTable()
Returns the database table.
in Query at line 268
bool
isDistinct()
Is it a distict select?
in Query at line 278
array
getColumns()
Returns the columns from which we are fetching data.
in Query at line 288
array
getWheres()
Returns WHERE clauses.
in Query at line 298
array
getJoins()
Returns JOIN clauses.
in Query at line 308
array
getGroupings()
Returns GROUP BY clauses.
in Query at line 318
array
getHavings()
Returns HAVING clauses.
in Query at line 328
array
getOrderings()
Returns ORDER BY clauses.
in Query at line 338
int|null
getLimit()
Returns the limit.
in Query at line 348
int|null
getOffset()
Returns the offset.
in Query at line 358
bool|string|null
getLock()
Returns the lock.
in Query at line 368
string|null
getPrefix()
Returns the prefix.
in Query at line 380
protected Query
setOperation(Closure|Query|Subquery $query, string $operation)
Adds a set operation.
in Query at line 435
Query
intersectAll(Closure|Query|Subquery $query)
Adds a INTERSECT ALL operation.
in Query at line 536
Query
where(string|array|Closure $column, string|null $operator = null, mixed $value = null, string $separator = 'AND')
Adds a WHERE clause.
in Query at line 575
Query
whereRaw(string|array $column, string|array|null $operator = null, string|null $raw = null, string $separator = 'AND')
Adds a raw WHERE clause.
in Query at line 600
Query
orWhere(string|array|Closure $column, string|null $operator = null, mixed $value = null)
Adds a OR WHERE clause.
in Query at line 613
Query
orWhereRaw(string|array $column, string|array|null $operator = null, string|null $raw = null)
Adds a raw OR WHERE clause.
in Query at line 628
Query
between(string $column, mixed $value1, mixed $value2, string $separator = 'AND', bool $not = false)
Adds a BETWEEN clause.
in Query at line 651
Query
orBetween(string $column, mixed $value1, mixed $value2)
Adds a OR BETWEEN clause.
in Query at line 664
Query
notBetween(string $column, mixed $value1, mixed $value2)
Adds a NOT BETWEEN clause.
in Query at line 677
Query
orNotBetween(string $column, mixed $value1, mixed $value2)
Adds a OR NOT BETWEEN clause.
in Query at line 691
Query
in(string $column, array|Raw|Closure|Subquery $values, string $separator = 'AND', bool $not = false)
Adds a IN clause.
in Query at line 758
Query
isNull(mixed $column, string $separator = 'AND', bool $not = false)
Adds a IS NULL clause.
in Query at line 812
Query
exists(Closure|Subquery $query, string $separator = 'AND', bool $not = false)
Adds a EXISTS clause.
in Query at line 73
Query
join(string $table, string|Closure $column1 = null, string $operator = null, string $column2 = null, string $type = 'INNER', bool $raw = false)
Adds a JOIN clause.
in Query at line 909
Query
joinRaw(string $table, string $column1, string $operator, string $raw, string $type = 'INNER')
Adds a raw JOIN clause.
in Query at line 923
Query
leftJoin(string $table, string|Closure $column1 = null, string $operator = null, string $column2 = null)
Adds a LEFT OUTER JOIN clause.
in Query at line 937
Query
leftJoinRaw(string $table, string $column1, string $operator, string $raw)
Adds a raw LEFT OUTER JOIN clause.
in Query at line 964
Query
having(string $column, string $operator, mixed $value, string $separator = 'AND')
Adds a HAVING clause.
in Query at line 986
Query
havingRaw(string $raw, string $operator, mixed $value, string $separator = 'AND')
Adds a raw HAVING clause.
in Query at line 999
Query
orHaving(string $column, string $operator, mixed $value)
Adds a OR HAVING clause.
in Query at line 1012
Query
orHavingRaw(string $raw, string $operator, mixed $value)
Adds a raw OR HAVING clause.
in Query at line 1024
Query
orderBy(string|array $columns, string $order = 'ASC')
Adds a ORDER BY clause.
in Query at line 1042
Query
orderByRaw(string $raw, string $order = 'ASC')
Adds a raw ORDER BY clause.
in Query at line 1171
mixed
column(string $column = null)
Executes a SELECT query and returns the value of the chosen column of the first row of the result set.
in Query at line 1189
array
columns(string $column = null)
Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.
in Query at line 1208
array
pairs(string $key, string $value)
Executes a SELECT query and returns an array where the first column is used as keys and the second as values.
in Query at line 1223
protected mixed
fetchFirst(mixed ...$fetchMode)
Executes a SELECT query and returns the first row of the result set.
in Relation at line 171
mixed
first()
Returns a single record from the database.
in Query at line 1258
protected array|ResultSet
fetchAll(bool $returnResultSet, mixed ...$fetchMode)
Executes a SELECT query and returns an array containing all of the result set rows.
in Query at line 1283
protected Generator
fetchYield(mixed ...$fetchMode)
Executes a SELECT query and returns a generator that lets you iterate over the results.
in Query at line 1305
protected int
paginationCount()
Returns the number of records that the query will return.
in Query at line 449
batch(Closure $processor, int $batchSize = 1000, int $offsetStart = 0, int $offsetEnd = null)
Fetches data in batches and passes them to the processor closure.
in Query at line 1393
protected mixed
aggregate(string $function, string|array $column)
Sets the selected column of the query to the chosen aggreate.
Executes the query and returns the result if not in subquery context.
in Query at line 1411
int
min(string $column)
Returns the minimum value for the chosen column.
in Query at line 1422
int
max(string $column)
Returns the maximum value for the chosen column.
in Query at line 1433
int
sum(string $column)
Returns sum of all the values in the chosen column.
in Query at line 1444
float
avg(string $column)
Returns the average value for the chosen column.
in Query at line 1455
int
count(string $column = '*')
Returns the number of rows.
in Query at line 1466
int
countDistinct(string|array $column)
Returns the number of distinct values of the chosen column.
in Query at line 86
bool
insert(array $values = [])
Inserts data into the chosen table.
in Query at line 1491
int|bool
insertAndGetId(array $values, string $primaryKey = 'id')
Inserts data into the chosen table and returns the auto increment id.
in Query at line 114
int
update(array $values)
Updates data from the chosen table.
in Query at line 142
int
increment(string $column, int $increment = 1)
Increments column value.
in Query at line 164
int
decrement(string $column, int $decrement = 1)
Decrements column value.
in Query at line 186
int
delete()
Deletes data from the chosen table.
in Query at line 214
ORM
get(int $id, array $columns = [])
Returns a record using the value of its primary key.
in Query at line 319
protected array
parseIncludes()
Parses includes.
in Query at line 356
protected
loadIncludes(array $results)
Load includes.
in Query at line 374
protected array
hydrateModelsAndLoadIncludes(mixed $results)
Returns hydrated models.
in Query at line 466
Query
__call(string $name, array $arguments)
Magic method that allows us to call model scopes.
in Relation at line 79
protected string
getForeignKey()
Returns the foreign key.
in Relation at line 95
protected array
keys(array $results)
Returns the keys used to eagerly load records.
in Relation at line 110
protected
lazyCriterion()
Sets the criterion used when lazy loading related records.
in Relation at line 121
protected Relation
eagerCriterion(array $keys)
Sets the criterion used when eager loading related records.
in Relation at line 136
protected ResultSet
eagerLoadChunked(array $keys)
Eager loads records in chunks.
in Relation at line 158
protected
adjustQuery()
Adjusts the query.
in HasOneOrMany at line 23
ORM
create(mixed $related)
Creates a related record.
at line 27
eagerLoad(array $results, string $relation, Closure $criteria = null, array $includes)
Eager loads related records and matches them with their parent records.
at line 56
ResultSet
getRelated()
Returns a related result set from the database.