2626import io .objectbox .internal .ToManyGetter ;
2727import io .objectbox .internal .ToOneGetter ;
2828
29- @ Internal
30- @ Immutable
3129/**
3230 * Meta info describing a relation including source and target entity.
3331 */
32+ @ Internal
33+ @ Immutable
3434public class RelationInfo <TARGET > implements Serializable {
3535 private static final long serialVersionUID = 7412962174183812632L ;
3636
3737 public final EntityInfo sourceInfo ;
3838 public final EntityInfo <TARGET > targetInfo ;
3939
40- /** For relations based on a target ID property (null for stand-alone relations ). */
40+ /** For relations based on a target ID property (null otherwise ). */
4141 public final Property targetIdProperty ;
4242
43+ /** For ToMany relations based on ToMany backlinks (0 otherwise). */
44+ public final int targetRelationId ;
45+
4346 /** Only set for ToOne relations */
4447 public final ToOneGetter toOneGetter ;
4548
4649 /** Only set for ToMany relations */
4750 public final ToManyGetter toManyGetter ;
4851
49- /** For ToMany relations based on backlinks (null for stand-alone relations ). */
52+ /** For ToMany relations based on ToOne backlinks (null otherwise ). */
5053 public final ToOneGetter backlinkToOneGetter ;
5154
5255 /** For stand-alone to-many relations (0 otherwise). */
@@ -61,6 +64,7 @@ public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, Proper
6164 this .targetInfo = targetInfo ;
6265 this .targetIdProperty = targetIdProperty ;
6366 this .toOneGetter = toOneGetter ;
67+ this .targetRelationId = 0 ;
6468 this .backlinkToOneGetter = null ;
6569 this .toManyGetter = null ;
6670 this .relationId = 0 ;
@@ -76,22 +80,38 @@ public RelationInfo(EntityInfo sourceInfo, EntityInfo<TARGET> targetInfo, ToMany
7680 this .targetIdProperty = targetIdProperty ;
7781 this .toManyGetter = toManyGetter ;
7882 this .backlinkToOneGetter = backlinkToOneGetter ;
83+ this .targetRelationId = 0 ;
7984 this .toOneGetter = null ;
8085 this .relationId = 0 ;
8186 }
8287
8388 /**
84- * Stand -alone ToMany.
89+ * ToMany as a ToMany backlink or stand -alone ToMany.
8590 */
8691 public RelationInfo (EntityInfo sourceInfo , EntityInfo <TARGET > targetInfo , ToManyGetter toManyGetter ,
87- int relationId ) {
92+ int relationId , boolean isBacklink ) {
8893 this .sourceInfo = sourceInfo ;
8994 this .targetInfo = targetInfo ;
90- this .relationId = relationId ;
9195 this .toManyGetter = toManyGetter ;
9296 this .targetIdProperty = null ;
9397 this .toOneGetter = null ;
9498 this .backlinkToOneGetter = null ;
99+ if (isBacklink ) {
100+ this .relationId = 0 ;
101+ this .targetRelationId = relationId ;
102+ } else {
103+ // stand-alone
104+ this .relationId = relationId ;
105+ this .targetRelationId = 0 ;
106+ }
107+ }
108+
109+ /**
110+ * Stand-alone ToMany.
111+ */
112+ public RelationInfo (EntityInfo sourceInfo , EntityInfo <TARGET > targetInfo , ToManyGetter toManyGetter ,
113+ int relationId ) {
114+ this (sourceInfo , targetInfo , toManyGetter , relationId , false );
95115 }
96116
97117 @ Override
0 commit comments