@@ -148,6 +148,14 @@ public boolean isNull() {
148
148
return getTargetId () == 0 && target == null ;
149
149
}
150
150
151
+ /**
152
+ * Sets or clears the target ID in the source entity. Pass 0 to clear.
153
+ * <p>
154
+ * Put the source entity to persist changes.
155
+ * If the ID is not 0 creates a relation to the target entity with this ID, otherwise dissolves it.
156
+ *
157
+ * @see #setTarget
158
+ */
151
159
public void setTargetId (long targetId ) {
152
160
if (virtualProperty ) {
153
161
this .targetId = targetId ;
@@ -172,10 +180,13 @@ void setAndUpdateTargetId(long targetId) {
172
180
}
173
181
174
182
/**
175
- * Sets the relation ID in the enclosed entity to the ID of the given target entity.
176
- * If the target entity was not put in the DB yet (its ID is 0), it will be put before to get its ID.
183
+ * Sets or clears the target entity and ID in the source entity. Pass null to clear.
184
+ * <p>
185
+ * Put the source entity to persist changes.
186
+ * If the target entity was not put yet (its ID is 0), it will be stored when the source entity is put.
187
+ *
188
+ * @see #setTargetId
177
189
*/
178
- // TODO provide a overload with a ToMany parameter, which also gets updated
179
190
public void setTarget (@ Nullable final TARGET target ) {
180
191
if (target != null ) {
181
192
long targetId = relationInfo .targetInfo .getIdGetter ().getId (target );
@@ -189,10 +200,11 @@ public void setTarget(@Nullable final TARGET target) {
189
200
}
190
201
191
202
/**
192
- * Sets the relation ID in the enclosed entity to the ID of the given target entity and puts the enclosed entity.
193
- * If the target entity was not put in the DB yet (its ID is 0), it will be put before to get its ID.
203
+ * Sets or clears the target entity and ID in the source entity, then puts the source entity to persist changes.
204
+ * Pass null to clear.
205
+ * <p>
206
+ * If the target entity was not put yet (its ID is 0), it will be put before the source entity.
194
207
*/
195
- // TODO provide a overload with a ToMany parameter, which also gets updated
196
208
public void setAndPutTarget (@ Nullable final TARGET target ) {
197
209
ensureBoxes (target );
198
210
if (target != null ) {
@@ -212,9 +224,13 @@ public void setAndPutTarget(@Nullable final TARGET target) {
212
224
}
213
225
214
226
/**
215
- * Sets the relation ID in the enclosed entity to the ID of the given target entity and puts both entities.
227
+ * Sets or clears the target entity and ID in the source entity,
228
+ * then puts the target (if not null) and source entity to persist changes.
229
+ * Pass null to clear.
230
+ * <p>
231
+ * When clearing the target entity, this does not remove it from its box.
232
+ * This only dissolves the relation.
216
233
*/
217
- // TODO provide a overload with a ToMany parameter, which also gets updated
218
234
public void setAndPutTargetAlways (@ Nullable final TARGET target ) {
219
235
ensureBoxes (target );
220
236
if (target != null ) {
0 commit comments