RelationalModel<T extends RelationalModel<T> > class
abstract
Abstract base class that provides RelationalModel-style CRUD operations for any model.
Each model must:
- Implementers
Constructors
Properties
- autoIncrementPrimary → bool
-
no setter
- dbService → RelationalDatabaseAdapter
-
Universal DB service
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
loadedIncludes
↔ Map<
String, RelationScope> -
Track which relations were included and loaded last
getter/setter pair
-
pivot
↔ Map<
String, dynamic> ? -
getter/setter pair
- primaryKey → String
-
no setter
-
resolvedRelations
↔ Map<
String, dynamic> -
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- softDeletes → bool
-
no setter
- table → String
-
Table name this model belongs to (e.g. "rooms", "bots").
no setter
- timestamps → bool
-
no setter
Methods
-
all(
{dynamic include = const []}) → Future< List< T> > - Find multiple records by a list of IDs.
-
associate(
String relName, RelationalModel< RelationalModel> parent) → void -
attach(
String relName, RelationalModel< RelationalModel> child) → void - HAS ONE / HAS MANY: parent.attach('hosts', child), sets FK on child, requires save()
-
attachMany(
String relName, List< RelationalModel< children) → voidRelationalModel> > -
attachPivot(
String relName, Map< String, dynamic> ? pivot}) → Future<void> - Attach with pivot table. Saved into db
-
delete(
{Map< String, dynamic> ? where}) → Future<int> - Delete this model safely through RelationalModel.
-
detachPivot(
String relName, ) → Future< void> - Detach from pivot table by related model ID. Deleted from DB immediately.
-
find(
dynamic pkValue, {dynamic include = const {}}) → Future< T?> -
Find a record by primary key (
id). -
findMany(
List pkValues, {dynamic include = const []}) → Future< List< T> > - Find multiple records by a list of IDs.
-
findOrFail(
dynamic pkValue, {List< String> include = const []}) → Future<T> -
Find a record by primary key (
id) or throw if not found. -
firstWhere(
String column, dynamic value) → Future< T?> - Get the first record matching a condition.
-
fromJson(
Map< String, dynamic> json) → T -
fromMap(
Map< String, dynamic> map) → T -
getLoadedIncludePaths(
) → List< String> - Get names of loaded includes
-
getLoadedIncludes(
) → Map< String, RelationScope> - Get loaded includes
-
getRelation(
String name) → dynamic - Get relation
-
getRelations(
) → dynamic - Get relations
-
hydrate(
List< Map< rows) → Hydrator<String, dynamic> >T> - Hydrate method. Hydrate either a single row or many (no async here).
-
hydrateMany(
List< Map< rows) → List<String, dynamic> >T> - Hydrate many rows into models (no query).
-
hydrateOne(
Map< String, dynamic> row) → T - Hydrate a single row into a model (no query).
-
loadRelations(
List< T> items, {dynamic include}) → Future<List< T> > -
mergeIncludes(
dynamic newIncludes, Map< String, RelationScope> existingIncludes) → Map<String, RelationScope> -
mergeRelationScopes(
RelationScope newScope, RelationScope? oldScope) → RelationScope - Merge relation scopes
-
normalizeIncludes(
dynamic includesInput) → Map< String, RelationScope> - Normalize inputs
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
query(
) → Query< T> -
refresh(
{dynamic include, bool append = true}) → Future< T> - Refresh model
-
relations(
) → Map< String, Relation< T, dynamic> > - Each model overrides this to declare relations
-
save(
{bool autoTimestamps = true, bool autoId = true}) → Future< T?> - Save itself, auto-generates UUID if needed, returns fresh hydrated model.
-
serialize(
) → Map< String, dynamic> - Serialize any model to Map (shortcut for toJson)
-
setAttribute(
String column, dynamic value) → void -
setLoadedIncludes(
Map< String, RelationScope> includes) → void - Mark includes as loaded
-
setRelation(
String name, dynamic value) → void - Set relation
-
toJson(
) → Map< String, dynamic> -
toMap(
) → Map< String, dynamic> -
toString(
) → String -
A string representation of this object.
inherited
-
update(
{String? where, List? params}) → Future< int> - Update this model in the database.
-
updatePivot(
String relName, Map< String, dynamic> values) → Future<int> - Update pivot data between this model and a related model. Updates DB immediately. Does NOT reload models.
-
where(
String column, dynamic value) → Future< List< T> > - Get all records matching a condition.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
create<
T extends RelationalModel< (T> >T model, Map< String, dynamic> data) → Future<T> - Create model from data
-
insert<
T extends RelationalModel< (T> >T model, Map< String, dynamic> data) → Future<void> - Insert this model into the database. Returns the inserted row ID.
-
insertGetId<
T extends RelationalModel< (T> >T model, Map< String, dynamic> data) → Future<int> - Insert and get id