Cindel models relationships between collections usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/mainser/cindel/llms.txt
Use this file to discover all available pages before exploring further.
CindelLink<T> for to-one relations and CindelLinks<T> for to-many relations. These link fields are declared directly on your model classes and are managed by the generated schema. A third annotation, @Backlink, marks a field as the read-only inverse of a forward link so you can traverse a relationship from either end without storing redundant data.
Declaring Links
Add aCindelLink<T> field to hold a reference to a single related object, or a CindelLinks<T> field to hold references to a set of related objects. Both types start unloaded — the related objects are not fetched automatically when the owner is read from storage:
Song.featuredArtists is the forward CindelLinks<Artist> relation — it stores the artist ids. Song.primaryArtist is the forward CindelLink<Artist> relation. Artist.songs is the backlink — it declares to: 'featuredArtists', meaning it reads from the featuredArtists link on the Song collection to find all songs that reference a given artist.
Persisting Links
Both linked objects must already be persisted before you can save a link. Callsave() on the link inside a write transaction after putting both objects:
CindelLinks<T>, use add(object) to stage items before calling save(). For CindelLink<T>, assign directly to the value property.
Loading Links
After reading an object from storage, callload() on each link field you want to access. Loading is explicit and asynchronous:
CindelLink<T>— read throughlink.value, which isnullwhen no object is linked or when the linked object has been deletedCindelLinks<T>— iterate directly (it extendsIterable<T>) or calltoList()for a snapshot
Using Backlinks
@Backlink(to: 'forwardFieldName') marks a field as the read-only inverse of a forward link declared on the related collection. The to argument must match the Dart field name of the forward link:
save() on a backlink throws a StateError at runtime — the relationship is always managed from the forward side.
Removing Links
To disconnect a linked object, update the forward link and callsave() again. For CindelLink<T> set value to null. For CindelLinks<T> call remove(object) or clear the set and then call save():
reset() clears the in-memory state without touching persisted ids — it is useful when you want to discard a locally staged change before calling save().