@@ -9,11 +9,17 @@ import 'modelentity.dart';
99class ModelProperty {
1010 IdUid id;
1111
12+ /// See [name] .
1213 late String _name;
1314
1415 late int _type, _flags;
1516 IdUid ? _indexId;
1617 ModelEntity ? entity;
18+ 19+ /// If this [isRelation] , the name of the field of the ToOne.
20+ String ? relationField;
21+ 22+ /// If this [isRelation] , the name of the entity class the ToOne targets.
1723 String ? relationTarget;
1824
1925 /// The optional [HnswIndex] parameters of this property.
@@ -34,6 +40,9 @@ class ModelProperty {
3440 // whether the user requested UID information (started a rename process)
3541 final bool uidRequest;
3642
43+ /// The name of the property. Except if [isRelation] , this is also the name of
44+ /// the associated Dart field. If [isRelation] use [relationField] to get the
45+ /// name of the ToOne field.
3746 String get name => _name;
3847
3948 set name (String ? value) {
@@ -121,6 +130,7 @@ class ModelProperty {
121130 required int type,
122131 required int flags,
123132 IdUid ? indexId,
133+ this .relationField,
124134 this .relationTarget,
125135 this .hnswParams,
126136 this .externalName,
@@ -133,6 +143,7 @@ class ModelProperty {
133143
134144 ModelProperty .fromMap (Map <String , dynamic > data, this .entity)
135145 : id = IdUid .fromString (data[ModelPropertyKey .id] as String ? ),
146+ relationField = data[ModelPropertyKey .relationField] as String ? ,
136147 relationTarget = data[ModelPropertyKey .relationTarget] as String ? ,
137148 _dartFieldType = data[ModelPropertyKey .dartFieldType] as String ? ,
138149 uidRequest = data[ModelPropertyKey .uidRequest] as bool ? ?? false ,
@@ -164,6 +175,9 @@ class ModelProperty {
164175 ret[ModelPropertyKey .relationTarget] = relationTarget;
165176 }
166177 if (! forModelJson) {
178+ if (relationField != null ) {
179+ ret[ModelPropertyKey .relationField] = relationField;
180+ }
167181 if (_dartFieldType != null ) {
168182 ret[ModelPropertyKey .dartFieldType] = _dartFieldType;
169183 }
@@ -216,6 +230,9 @@ class ModelProperty {
216230 result += ' index:$type ' ;
217231 }
218232
233+ if (relationField != null ) {
234+ result += ' relField:$relationField ' ;
235+ }
219236 if (relationTarget != null ) {
220237 result += ' relTarget:$relationTarget ' ;
221238 }
@@ -231,6 +248,7 @@ class ModelPropertyKey {
231248 static const String indexId = 'indexId' ;
232249 static const String type = 'type' ;
233250 static const String flags = 'flags' ;
251+ static const String relationField = 'relationField' ;
234252 static const String relationTarget = 'relationTarget' ;
235253 static const String dartFieldType = 'dartFieldType' ;
236254 static const String uidRequest = 'uidRequest' ;
0 commit comments