Skip to content

Commit b679463

Browse files
ToOne docs: update setTarget() docs to match implementation.
Docs regression introduced with c598266 ToOne puts via cursor if necessary Also match wording (source entity vs enclosing entity, etc.).
1 parent 9d3692e commit b679463

File tree

1 file changed

+24
-8
lines changed
  • objectbox-java/src/main/java/io/objectbox/relation

1 file changed

+24
-8
lines changed

objectbox-java/src/main/java/io/objectbox/relation/ToOne.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ public boolean isNull() {
148148
return getTargetId() == 0 && target == null;
149149
}
150150

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+
*/
151159
public void setTargetId(long targetId) {
152160
if (virtualProperty) {
153161
this.targetId = targetId;
@@ -172,10 +180,13 @@ void setAndUpdateTargetId(long targetId) {
172180
}
173181

174182
/**
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
177189
*/
178-
// TODO provide a overload with a ToMany parameter, which also gets updated
179190
public void setTarget(@Nullable final TARGET target) {
180191
if (target != null) {
181192
long targetId = relationInfo.targetInfo.getIdGetter().getId(target);
@@ -189,10 +200,11 @@ public void setTarget(@Nullable final TARGET target) {
189200
}
190201

191202
/**
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.
194207
*/
195-
// TODO provide a overload with a ToMany parameter, which also gets updated
196208
public void setAndPutTarget(@Nullable final TARGET target) {
197209
ensureBoxes(target);
198210
if (target != null) {
@@ -212,9 +224,13 @@ public void setAndPutTarget(@Nullable final TARGET target) {
212224
}
213225

214226
/**
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.
216233
*/
217-
// TODO provide a overload with a ToMany parameter, which also gets updated
218234
public void setAndPutTargetAlways(@Nullable final TARGET target) {
219235
ensureBoxes(target);
220236
if (target != null) {

0 commit comments

Comments
 (0)