|
22 | 22 | import java.lang.annotation.Target; |
23 | 23 |
|
24 | 24 | /** |
25 | | - * For a ToOne, changes the name of the property to store the target object ID in from the default name: |
| 25 | + * For a ToOne, changes the name of its associated target ID (or "relation") property. |
26 | 26 | * <p> |
27 | 27 | * <pre>{@code |
28 | 28 | * @Entity |
29 | 29 | * public class Order { |
30 | | - * @TargetIdProperty("customerRenamedTargetId") |
| 30 | + * // Change from default "customerId" to "customerRef" |
| 31 | + * @TargetIdProperty("customerRef") |
31 | 32 | * ToOne<Customer> customer; |
32 | | - * long customerRenamedTargetId; |
| 33 | + * // Optional: expose target ID property (using changed name) |
| 34 | + * long customerRef; |
33 | 35 | * } |
34 | 36 | * }</pre> |
35 | 37 | * <p> |
36 | | - * By default, a target ID property named like the ToOne property with the suffix "Id" is created implicitly (so without |
37 | | - * defining it in the @Entity class). Using the example above, without the annotation a "virtual" property named |
38 | | - * {@code long customerId} would be created. |
| 38 | + * A target ID property is implicitly created (so without defining it in the {@link Entity @Entity} class) for each |
| 39 | + * ToOne and stores the ID of the referenced target object. By default, it's named like the ToOne field plus the suffix |
| 40 | + * "Id" (for example {@code customerId}). |
39 | 41 | * <p> |
40 | | - * Exposing the target ID as an actual field (so not necessarily renamed using this annotation) can be useful for other |
41 | | - * parsers or serializers, like for JSON. |
| 42 | + * Like in the example above, it's still possible to expose the target ID property as an actual field (useful for other |
| 43 | + * parsers or serializers, like for JSON). But make sure to use the changed name for the field. |
42 | 44 | * <p> |
43 | 45 | * See the <a href="https://docs.objectbox.io/relations">relations documentation</a> for details. |
44 | 46 | */ |
|
0 commit comments