@@ -8,48 +8,43 @@ import '../store.dart';
88import '../transaction.dart' ;
99import 'info.dart' ;
1010
11- /// A lazily loaded `List` of target objects representing a to-many relation,
12- /// a unidirectional link from a "source" entity to multiple objects of a
13- /// "target" entity.
14- ///
15- /// It tracks changes (adds and removes) that can be later applied (persisted)
16- /// to the database. This happens either when the source entity of this relation
17- /// is put or using [applyToDb] . For some important details about applying
18- /// changes, see the notes about relations of [Box.put] .
19- ///
20- /// The objects are loaded lazily on first access of this list, and then cached.
21- /// Subsequent calls to any method, like [length] , do not query the database,
22- /// even if the relation was changed elsewhere. To get the latest data [Box.get]
23- /// the source object again.
24- ///
25- /// You can:
26- /// - [add] new objects to the relation.
27- /// - [removeAt] target objects from the relation at a specific list index.
28- /// - [remove] target objects from the relation by an ID.
11+ /// A to-many relation of an entity that references multiple objects of a "target" entity [EntityT] .
2912///
13+ /// Example:
3014/// ```
15+ /// @Entity()
3116/// class Student {
3217/// final teachers = ToMany<Teacher>();
3318/// }
19+ /// ```
3420///
35- /// // Example 1: create a relation
36- /// final teacher1 = Teacher();
37- /// final teacher2 = Teacher();
21+ /// Implements the `List` interface and uses lazy initialization.
22+ /// The target objects are only read from the database when the list is first accessed.
3823///
39- /// final student1 = Student();
40- /// student1.teachers.add(teacher1);
41- /// student1.teachers.add(teacher2);
24+ /// Tracks when target objects are added and removed. Common usage:
25+ /// - [add] target objects to the relation.
26+ /// - [remove] target objects from the relation.
27+ /// - [removeAt] target objects at a specific index.
4228///
43- /// final student2 = Student();
44- /// student2.teachers.add(teacher2);
29+ /// To apply (persist) the changes to the database, call [applyToDb] or put the object with the ToMany.
30+ /// For important details, see the notes about relations of [Box.put] .
4531///
46- /// // saves students as well as teachers in the database
47- /// store.box<Student>().putMany([student1, student2]);
32+ /// ```
33+ /// // Example 1: add target objects to a relation
34+ /// student.teachers.add(teacher1);
35+ /// student.teachers.add(teacher2);
36+ /// store.box<Student>().put(student);
4837///
49- /// // Example 2: remove a relation
50- /// student.teachers.removeAt(index)
51- /// student.teachers.applyToDb(); // or store.box<Student>().put(student);
38+ /// // Example 2: remove a target object from the relation
39+ /// student.teachers.removeAt(index);
40+ /// student.teachers.applyToDb();
41+ /// // or store.box<Student>().put(student);
5242/// ```
43+ ///
44+ /// In the database, the target objects are referenced by their IDs, which are
45+ /// persisted as part of the relation of the object with the ToMany.
46+ ///
47+ /// To get all objects with a ToMany that reference a target object, see [Backlink] .
5348class ToMany <EntityT > extends Object with ListMixin <EntityT > {
5449 /// Store-related configuration attached to this.
5550 ///
0 commit comments