OneToOne class
OneToOne relationship annotation
Defines a one-to-one relationship between entities. One side must be the owning side (has the FK column), the other is the inverse side.
Example:
// In UserEntity (inverse side - no FK column)
@OneToOne(
targetEntity: ProfileEntity,
mappedBy: 'user', // Field name in ProfileEntity
)
ProfileEntity? profile;
// In ProfileEntity (owning side - has FK column)
@OneToOne(
targetEntity: UserEntity,
foreignKey: 'user_id',
isOwning: true,
onDelete: RelationAction.cascade,
)
UserEntity? user;
Constructors
- OneToOne({required Type targetEntity, String? mappedBy, String? foreignKey, String referencedColumn = 'id', bool isOwning = false, bool cascadeDelete = false, bool lazyLoad = true, bool eagerLoad = false, bool nullable = true, bool unique = true, 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
- foreignKey → String?
-
Foreign key column name in this entity's table
Required on the owning side (the side that has the FK column)
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isOwning → bool
-
Whether this is the owning side (has the FK column)
final
- lazyLoad → bool
-
Whether to lazy load the relationship
final
- mappedBy → String?
-
Field name in the target entity that owns the relationship
Used on the inverse side to reference the owning side's field
final
- nullable → bool
-
Whether this relationship is nullable
final
- onDelete → RelationAction
-
Action to take on delete of referenced entity
final
- onUpdate → RelationAction
-
Action to take on update of referenced entity
final
- referencedColumn → String
-
Referenced column in the target entity (usually 'id')
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- targetEntity → Type
-
The target entity type for this relationship
final
- unique → bool
-
Whether to enforce uniqueness on the FK column (ensures 1:1)
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