OneToMany class

OneToMany relationship annotation

Defines a one-to-many relationship between entities. This is the owning side - a FK column will be created in the target entity's table. The FK column name is automatically derived as {ownerTableName}_id (singular, snake_case). The target table name is automatically resolved from the target entity's @Entity annotation.

Example:

// In UserEntity (tableName: 'users') - owns the relationship
// Automatically creates user_id FK column in posts table (resolved from PostEntity's @Entity)
@OneToMany(targetEntity: PostEntity)
List<PostEntity>? posts;

// With explicit FK (if target entity uses a different FK column name):
@OneToMany(
  targetEntity: PurchasesEntity,
)
List<PurchasesEntity>? purchases;

Constructors

OneToMany({required Type targetEntity, bool cascadeDelete = false, bool lazyLoad = true, bool eagerLoad = false, RelationAction onDelete = RelationAction.noAction, RelationAction onUpdate = RelationAction.noAction})
const

Properties

cascadeDelete → bool
Whether to cascade delete operations
final
eagerLoad → bool
Whether to eager load the relationship
final
hashCode → int
The hash code for this object.
no setterinherited
lazyLoad → bool
Whether to lazy load the relationship
final
onDelete → RelationAction
Action to take on delete of this entity
final
onUpdate → RelationAction
Action to take on update of this entity
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
targetEntity → Type
The target entity type for this relationship
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited