ToOne<EntityT> class Null safety

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:

class Order {
  final customer = ToOne<Customer>();

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

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

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

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

// Example 2: remove a relation = null
// ... or ...
order.customer.targetId = 0


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


hashCode int
The hash code for this object. [...]
read-only, inherited
hasValue bool
Whether the relation field has a value stored. Otherwise it's null.
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
target ↔ EntityT?
Get target object. If it's the first access, this reads from DB.
read / write
targetId int
Get ID of a relation target object.
read / write


attach(Store store) → void
Initialize the relation field, attaching it to the store. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]