ToOne<EntityT> class

Manages a to-one relation, an unidirectional link from a "source" entity to a "target" entity. The target object is referenced by its ID, which is persisted in the source object.

You can:

@Entity()
class Order {
  final customer = ToOne<Customer>();
  ...
}

// Example 1: create a relation
final order = Order(...);
final customer = Customer();
order.customer.target = customer;

// Or you could create the target object in place:
// order.customer.target = Customer()

// attach() must be called when creating new instances. On objects (e.g.
// "orders" in this example) read with box.get() its done automatically.
order.customer.attach(store);

// saves both [customer] and [order] in the database
store.box<Order>().put(order);


// Example 2: remove a relation

order.customer.target = null
// ... or ...
order.customer.targetId = 0

Constructors

ToOne({EntityT? target, int? targetId})
Create a ToOne relationship.

Properties

hashCode int
The hash code for this object.
no setterinherited
hasValue bool
Whether the relation field has a value stored. Otherwise it's null.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
target ↔ EntityT?
Get target object. If it's the first access, this reads from DB.
getter/setter pair
targetId int
Get ID of a relation target object.
getter/setter pair

Methods

attach(Store store) → void
Initialize the relation field, attaching it to the store.
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