Backlink constructor

const Backlink([
  1. String to = ''
])

Marks a ToMany field in an Entity class to indicate the relation should be created based on another relation by reversing the direction.

Pass the name of the relation the backlink should be based on (e.g. name of a ToOne or ToMany property in the target entity). Can be left empty if there is just a single relation from the target to the source entity.

This works as an "updatable view" of the original relation, and doesn't cause any more data to be stored in the database. Changes made to the backlink relation are reflected in the original direction.

Example (ToOne relation): one "Order" references one "Customer". The backlink to this is a to-many in the reverse direction: one "Customer" has a number of "Order"s.

class Order {
  final customer = ToOne<Customer>();
}
class Customer {
  @Backlink()
  final orders = ToMany<Customer>();
}

Example (ToMany relation): one "Student" references multiple "Teacher"s. The backlink to this: one "Teacher" has a number of "Student"s.

class Student {
  final teachers = ToMany<Teacher>();
}
class Teacher {
  @Backlink()
  final students = ToMany<Student>();
}

Implementation

const Backlink([this.to = '']);