io.realm.annotations
Implemented interfaces:
Annotation for defining a reverse relationship from one class to another. This annotation can only be added to a field of the type RealmResults .
To expose reverse relationships for use, create a declaration as follows:
public class Person extends RealmObject { String name; Dog dog; // Normal relation } public class Dog extends RealmObject { // This holds all Person objects with a relation to this Dog object (= linking objects) final RealmResults<Person> owners = null; } // Find all Dogs with at least one owner named John realm.where(Dog.class).equalTo("owners.name", "John").findAll();
In the above example `Person` is related to `Dog` through the field `dog`. This in turn means that an implicit reverse relationship exists between the class `Dog` and the class `Person`. This inverse relationship is made public and queryable by the `RealmResults` field annotated with `@LinkingObject`. This makes it possible to query properties of the dogs owner without having to manually maintain a "owner" field in the `Dog` class.Linking objects have the following properties:
El enlace lo mantiene Realm y solo funciona para objetos administrados.
Se pueden hacer querys como una relación normal.
They can be followed just like normal relation.
Se ignoran cuando se realiza un `copyToRealm().`
Se ignoran cuando se realiza un `copyFromRealm().`
They are ignored when using the various `createObjectFromJson*` and `createAllFromJson*` methods.
Listeners on an object with a `@LinkingObject` field will not be triggered if the linking objects change, e.g: if another object drops a reference to this object.
In addition, they have the following restrictions:
@Ignore takes precedence. A @LinkingObjects annotation on @Ignore field will be ignored.
The annotated field cannot be @Required.
The annotated field must be `final`.
The annotation argument (the name of the backlinked field) is required.
The annotation argument must be a simple field name. It cannot contain periods ('.').
The annotated field must be of type `RealmResults<T>` where T is concrete class that extends `RealmModel`.
Tenga en cuenta que cuando la fuente de la referencia inversa ("perro" en el ejemplo anterior) es una `Lista`, existe una referencia inversa para cada referencia hacia adelante, incluso si ambas referencias hacia adelante apuntan al mismo objeto. Si la clase `Person` anterior se definiera como:
public class DogLover extends RealmObject { String name; List<Dog> dogs = new ArrayList<Dog>; } then the following code executes without error
Dog fido = new Dog(); DogLover john = new DogLover() john.dogs.add(fido); john.dogs.add(fido); assert john.dogs.size() == 2; assert fido.owners.size() == 2;
Consultar una relación inversa es como consultar cualquier RealmResults . Esto significa que una relación inversa no puede ser null, pero puede estar vacía (longitud 0). Es posible consultar campos en la clase fuente. Esto es equivalente a las consultas de enlace. Lea
Resumen de elementos opcionales
Modificador y Tipo | Optional Element and Description |
|---|---|
public String | The name of a field that contains a relation to an instance of the class containing this annotation. |
Element Detail
Valor |
|---|
The name of a field that contains a relation to an instance of the class containing this annotation. If this argument is not provided the annotation processor will abort with an Por defecto:
|