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:

@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. [...]
read-only, inherited
hasValue bool
Whether the relation field has a value stored. Otherwise it's null.
read-only
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

Methods

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. [...]
inherited
toString() String
A string representation of this object. [...]
inherited

Operators

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