HasManyThrough<R extends Model, I extends Model> class
Defines a distant one-to-many relationship linking a Parent to a Target via an Intermediate model.
e.g. A Country has many Posts through User:
Country (Parent) -> User (Intermediate, holds country_id) -> Post (Target, holds user_id).
- Inheritance
-
- Object
- QueryBuilder<
R> - Relation<
R> - HasManyThrough
Constructors
Properties
- columns → List
-
no setterinherited
-
creator
→ R Function(Map<
String, dynamic> ) -
This create empty instance of the model.
Example : creator({}).newQuery()
finalinherited
- distinctValue → bool
-
no setterinherited
- firstKey → String?
-
Foreign key on the Intermediate table pointing to the Parent.
final
-
groups
→ List<
String> -
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
havings
→ List<
Map< String, dynamic> > -
no setterinherited
-
intermediateCreator
→ I Function(Map<
String, dynamic> ) -
final
-
joins
→ List<
String> -
no setterinherited
- limitValue → int?
-
no setterinherited
- offsetValue → int?
-
no setterinherited
- orders → String?
-
no setterinherited
- parent → Model
-
The model instance that spawned this relationship query.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- secondKey → String?
-
Foreign key on the Target table pointing to the Intermediate model.
final
- table → String
-
finalinherited
-
unions
→ List<
Map< String, dynamic> > -
no setterinherited
-
wheres
→ List<
Map< String, dynamic> > -
no setterinherited
Methods
-
addConstraints(
) → void -
Configures the query for a single parent instance.
override
-
avg(
dynamic column) → Future< double?> -
inherited
-
cast<
U extends Model> (U newCreator(Map< String, dynamic> ), {U instanceFactory()?}) → QueryBuilder<U> -
Transitions the builder to a new Model type
Uwhile preserving query constraints.inherited -
count(
[dynamic column = '*']) → Future< int?> -
inherited
-
cursor(
{int batchSize = 100}) → Stream< R> -
Lazily streams results in chunks to minimize memory usage for large datasets.
inherited
-
delete(
) → Future< int> -
inherited
-
distinct(
) → QueryBuilder< R> -
Forces the query to return distinct results.
inherited
-
except(
QueryBuilder< Model> query) → QueryBuilder<R> -
Combines the result with another query using EXCEPT.
inherited
-
exists(
) → Future< bool> -
Checks existence by fetching a single record (Limit 1 optimization).
inherited
-
find(
dynamic id) → Future< R?> -
inherited
-
findOrFail(
dynamic id) → Future< R> -
Finds a model by ID or throws ModelNotFoundException.
inherited
-
first(
) → Future< R?> -
inherited
-
firstOrFail(
) → Future< R> -
Returns the first result or throws ModelNotFoundException.
inherited
-
get(
) → Future< List< R> > -
Executes the compiled query and hydrates results.
inherited
-
getKeys(
List< Model> models, String key) → List -
Extracts unique attribute values from a list of models, used to build
WHERE INclauses for batch fetching.inherited -
groupBy(
List columns) → QueryBuilder< R> -
Groups results by one or more columns.
inherited
-
groupByColumn(
dynamic column) → QueryBuilder< R> -
Convenience method for grouping by a single column.
inherited
-
having(
dynamic column, dynamic value, {String operator = '=', String boolean = 'AND'}) → QueryBuilder< R> -
Adds a HAVING clause to filter grouped results.
inherited
-
havingBetween(
dynamic column, dynamic min, dynamic max, {String boolean = 'AND'}) → QueryBuilder< R> -
Adds a HAVING BETWEEN clause.
inherited
-
havingNotNull(
dynamic column, {String boolean = 'AND'}) → QueryBuilder< R> -
Adds a HAVING clause that checks for NOT NULL.
inherited
-
havingNull(
dynamic column, {String boolean = 'AND'}) → QueryBuilder< R> -
Adds a HAVING clause that checks for NULL.
inherited
-
havingRaw(
String sql, {List bindings = const [], String boolean = 'AND'}) → QueryBuilder< R> -
Adds a raw HAVING clause for complex aggregate conditions.
inherited
-
insert(
Map values) → Future< int> -
Executes a raw INSERT into the database.
inherited
-
insertAll(
List< Map< values) → Future<String, dynamic> >bool> -
Executes a bulk INSERT into the database.
inherited
-
intersect(
QueryBuilder< Model> query) → QueryBuilder<R> -
Combines the result with another query using INTERSECT.
inherited
-
join(
String table, dynamic one, String operator, dynamic two) → QueryBuilder< R> -
inherited
-
leftJoin(
String table, dynamic one, String operator, dynamic two) → QueryBuilder< R> -
Adds a LEFT JOIN clause.
inherited
-
limit(
int limit) → QueryBuilder< R> -
inherited
-
match(
List< Model> models, String relationName, {ScopeCallback? scope, Map<String, ScopeCallback?> nested = const {}}) → Future<void> -
Eagerly loads relationships for a list of parents to avoid N+1 queries.
override
-
max(
dynamic column) → Future -
inherited
-
min(
dynamic column) → Future -
inherited
-
normKey(
dynamic v) → String? -
Normalizes keys to Strings to prevent map lookup failures caused by
Type mismatches (e.g.
intvsString) during result matching.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notExist(
) → Future< bool> -
inherited
-
offset(
int offset) → QueryBuilder< R> -
inherited
-
orderBy(
dynamic column, {String direction = 'ASC'}) → QueryBuilder< R> -
inherited
-
orHaving(
dynamic column, dynamic value, {String operator = '='}) → QueryBuilder< R> -
Adds an OR HAVING clause.
inherited
-
orHavingRaw(
String sql, [List bindings = const []]) → QueryBuilder< R> -
Adds an OR raw HAVING clause.
inherited
-
orWhere(
dynamic column, [dynamic value, String operator = '=']) → QueryBuilder< R> -
inherited
-
orWhereBetween(
dynamic column, List values) → QueryBuilder< R> -
Adds an "or between" where clause to the query.
inherited
-
orWhereColumn(
dynamic first, [dynamic second, String? operator]) → QueryBuilder< R> -
Adds an OR comparison between two columns to the query.
inherited
-
orWhereExists(
QueryBuilder< Model> query) → QueryBuilder<R> -
inherited
-
orWhereGroup(
void callback(QueryBuilder< R> query)) → QueryBuilder<R> -
Adds a nested WHERE group wrapped in parentheses: OR (...).
inherited
-
orWhereIn(
dynamic column, List values) → QueryBuilder< R> -
inherited
-
orWhereNotBetween(
dynamic column, List values) → QueryBuilder< R> -
Adds an "or not between" where clause to the query.
inherited
-
orWhereNotExists(
QueryBuilder< Model> query) → QueryBuilder<R> -
inherited
-
orWhereNotNull(
dynamic column) → QueryBuilder< R> -
inherited
-
orWhereNull(
dynamic column) → QueryBuilder< R> -
inherited
-
orWhereRaw(
String sql, [List bindings = const []]) → QueryBuilder< R> -
inherited
-
printAndDieRawSql(
) → void -
inherited
-
printQueryAndBindings(
) → QueryBuilder< R> -
inherited
-
printRawSql(
) → QueryBuilder< R> -
inherited
-
rightJoin(
String table, dynamic one, String operator, dynamic two) → QueryBuilder< R> -
Adds a RIGHT JOIN clause.
inherited
-
select(
List columns) → QueryBuilder< R> -
inherited
-
selectRaw(
String expression) → QueryBuilder< R> -
Adds aggregate columns to the selection without replacing existing columns.
inherited
-
sum(
dynamic column) → Future< num> -
inherited
-
toRawSql(
) → String -
inherited
-
toSql(
) → String -
Returns the raw SQL string compiled from current state.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
union(
QueryBuilder< Model> query) → QueryBuilder<R> -
Combines the result with another query using UNION.
inherited
-
unionAll(
QueryBuilder< Model> query) → QueryBuilder<R> -
Combines the result with another query using UNION ALL.
inherited
-
update(
Map values) → Future< int> -
inherited
-
watch(
) → Stream< List< R> > -
Returns a reactive stream that emits updated results when the table changes.
inherited
-
where(
dynamic column, [dynamic value, String operator = '=', String boolean = 'AND']) → QueryBuilder< R> -
Appends a condition to the query state.
inherited
-
whereBetween(
dynamic column, List values, {String boolean = 'AND', bool not = false}) → QueryBuilder< R> -
Adds a "between" where clause to the query.
inherited
-
whereColumn(
dynamic first, [dynamic second, String? operator, String boolean = 'AND']) → QueryBuilder< R> -
Adds a comparison between two columns to the query.
inherited
-
whereExists(
QueryBuilder< Model> query, {String boolean = 'AND', bool not = false}) → QueryBuilder<R> -
Nested query support via
EXISTS.inherited -
whereGroup(
void callback(QueryBuilder< R> query)) → QueryBuilder<R> -
Adds a nested WHERE group wrapped in parentheses: AND (...).
inherited
-
whereIn(
dynamic column, List values, {String boolean = 'AND'}) → QueryBuilder< R> -
Appends an
INclause.inherited -
whereNotBetween(
dynamic column, List values, {String boolean = 'AND'}) → QueryBuilder< R> -
Adds a "not between" where clause to the query.
inherited
-
whereNotExists(
QueryBuilder< Model> query) → QueryBuilder<R> -
inherited
-
whereNotNull(
dynamic column, {String boolean = 'AND'}) → QueryBuilder< R> -
inherited
-
whereNull(
dynamic column, {String boolean = 'AND'}) → QueryBuilder< R> -
inherited
-
whereRaw(
String sql, {List bindings = const [], String boolean = 'AND'}) → QueryBuilder< R> -
Raw SQL escape hatch. Use with caution.
inherited
-
withGlobalScope(
String name, ScopeCallback scope) → QueryBuilder< R> -
inherited
-
withoutGlobalScope(
String name) → QueryBuilder< R> -
inherited
-
withoutGlobalScopes(
) → QueryBuilder< R> -
inherited
-
withRelations(
dynamic relations) → QueryBuilder< R> -
Queues relationships for eager loading after the main query execution.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited