-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add info about querying relationships
- Loading branch information
Showing
18 changed files
with
516 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...ncludes/api-details/csharp/crud/read-query-inverse-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To query an inverse relationship in C#, you cannot use LINQ. Instead, pass a | ||
string predicate using RQL. The following example shows how you could find | ||
all Users who have Items that contain the word "oscillator". |
9 changes: 9 additions & 0 deletions
9
...ncludes/api-details/csharp/crud/read-query-to-many-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
An application could use the following object schemas to indicate | ||
that a Person may own multiple Dogs by including them in its ``dog`` | ||
property: | ||
|
||
.. literalinclude:: /examples/generated/dotnet/Relationships.snippet.one-to-many.cs | ||
:language: csharp | ||
|
||
To see the to-many relationship of Person to Dog, you query for the | ||
Person and get that person's Dogs. |
2 changes: 2 additions & 0 deletions
2
...includes/api-details/csharp/crud/read-query-to-one-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
To query a direct relationship, you can use LINQ syntax. | ||
See the following example for how to query a one-to-one relationship. |
16 changes: 16 additions & 0 deletions
16
.../includes/api-details/dart/crud/read-query-inverse-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
In Dart, there are two ways to query inverse relationships. | ||
|
||
You can use the :flutter-sdk:`getBacklinks() | ||
<realm/RealmObjectBase/getBacklinks.html>` method to retrieve an object at | ||
the origin of the relationship from the related object. | ||
|
||
Here, we use the ``getBacklinks()`` method to find any ``User`` objects that | ||
link to the specified tasks through the ``tasks`` backlinks property: | ||
|
||
.. literalinclude:: /examples/generated/flutter/backlinks_test.snippet.query-backlink-inverse-relationship.dart | ||
:language: dart | ||
|
||
You can also filter by inverse relationships using the | ||
``@links.<Type>.<Property>`` syntax. For example, a filter can match | ||
a ``Task`` object based on properties of the ``User`` | ||
object that references it. |
13 changes: 13 additions & 0 deletions
13
...udes/api-details/java/crud/read-query-inverse-relationship-java-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Consider the following relationship between classes ``Cat`` and | ||
``Human``. In this example, all cats link to their human (or | ||
multiple humans, if multiple human objects refer to the same cat). | ||
Realm calculates the owners of each cat for you based on the field | ||
name you provide to the ``@LinkingObjects`` annotation: | ||
|
||
.. include:: /examples/generated/java/sync/Cat.snippet.complete.java.rst | ||
|
||
.. include:: /examples/generated/java/sync/Human.snippet.complete.java.rst | ||
|
||
To query this relationship, use dot notation in a | ||
:ref:`query <sdks-java-filter-data>` to access any property | ||
of the linked object. |
13 changes: 13 additions & 0 deletions
13
...es/api-details/java/crud/read-query-inverse-relationship-kotlin-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Consider the following relationship between classes ``Dog`` and | ||
``Person``. In this example, all dogs link to their owner (or | ||
multiple owners, if multiple person objects refer to the same dog). | ||
Realm calculates the owners of each dog for you based on the field | ||
name you provide to the ``@LinkingObjects`` annotation: | ||
|
||
.. include:: /examples/generated/java/sync/Dog.snippet.complete.kt.rst | ||
|
||
.. include:: /examples/generated/java/sync/Person.snippet.complete.kt.rst | ||
|
||
To query this relationship, use dot notation in a | ||
:ref:`query <sdks-java-filter-data>` to access any property | ||
of the linked object. |
14 changes: 14 additions & 0 deletions
14
...ludes/api-details/java/crud/read-query-to-one-relationship-java-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Consider the following relationship between classes ``Human`` and | ||
``Cat``. This arrangement allows each human to own a single cat: | ||
|
||
.. literalinclude:: /examples/generated/java/sync/Human.snippet.complete.java | ||
:language: java | ||
:emphasize-lines: 12 | ||
:copyable: false | ||
|
||
.. literalinclude:: /examples/generated/java/sync/Cat.snippet.complete.java | ||
:language: java | ||
:copyable: false | ||
|
||
To query this relationship, use dot notation in a :ref:`query | ||
<sdks-java-filter-data>` to access any property of the linked object. |
14 changes: 14 additions & 0 deletions
14
...des/api-details/java/crud/read-query-to-one-relationship-kotlin-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Consider the following relationship between classes ``Person`` and | ||
``Dog``. This arrangement allows each person to own a single dog: | ||
|
||
.. literalinclude:: /examples/generated/java/sync/Person.snippet.complete.kt | ||
:language: kotlin | ||
:emphasize-lines: 10 | ||
:copyable: false | ||
|
||
.. literalinclude:: /examples/generated/java/sync/Dog.snippet.complete.kt | ||
:language: kotlin | ||
:copyable: false | ||
|
||
To query this relationship, use dot notation in a :ref:`query | ||
<sdks-java-filter-data>` to access any propertyof the linked object: |
10 changes: 10 additions & 0 deletions
10
...i-details/javascript/crud/read-query-inverse-relationship-js-ts-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
You can dynamically retrieve an object with an inverse relationship without | ||
defining a ``linkingObjects`` type in its schema. When you need to retrieve | ||
the linked object, call the :js-sdk:`Realm.Object.linkingObjects() | ||
<classes/Object.html#linkingObjects>` query. | ||
|
||
The ``.linkingObjects()`` method returns a :ref:`Results collection | ||
<sdks-read-access-results>` of objects whose property inverts the relationship. | ||
|
||
In this example, only one manufacturer makes the Sentra car model, so we | ||
can expect that manufacturer to be named Nissan. |
13 changes: 13 additions & 0 deletions
13
...ncludes/api-details/kotlin/crud/read-query-inverse-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
In the following example, a parent object of type ``User`` has an inverse | ||
relationship to a child object of type ``Post``. We can query the parent | ||
object's ``User.posts`` relationship ("User has many Posts") as well | ||
as the inverse ``Post.user`` relationship ("Post belongs to User"): | ||
|
||
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.query-inverse-relationship.kt | ||
:language: kotlin | ||
|
||
.. important:: Querying Inverse Relationship by Remapped Class Names | ||
|
||
If the inverse relationship property is an object type with a | ||
remapped (persisted) class name, you *must* use the remapped class | ||
name in the raw RQL query. |
2 changes: 2 additions & 0 deletions
2
...ncludes/api-details/kotlin/crud/read-query-to-many-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
In the following example, the ``Forest`` object type has a property called | ||
``nearbyPonds`` that is a ``RealmList`` of type ``Pond``. |
2 changes: 2 additions & 0 deletions
2
...includes/api-details/kotlin/crud/read-query-to-one-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
In the following example, the ``Frog`` object type has a property called | ||
``favoritePond`` of type ``Pond``. |
7 changes: 7 additions & 0 deletions
7
...des/api-details/objectivec/crud/read-query-inverse-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
You can query :swift-sdk:`RLMLinkingObjects | ||
<Classes.html#/c:objc(cs)RLMLinkingObjects>`, an auto-updating container type, | ||
to access zero or more objects that are linked to its owning model object | ||
through a property relationship. You can query ``RLMLinkingObjects`` with the | ||
same APIs and predicates as | ||
:swift-sdk:`RLMArray\<Element\> <Classes/RLMArray.html>` and | ||
:swift-sdk:`RLMResults\<Element\> <Classes/RLMResults.html>`. |
6 changes: 6 additions & 0 deletions
6
...includes/api-details/swift/crud/read-query-inverse-relationship-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
You can query :swift-sdk:`LinkingObjects <Structs/LinkingObjects.html>`, | ||
an auto-updating container type, to access zero or more objects that are | ||
linked to its owning model object through a property relationship. You can | ||
query ``LinkingObjects`` with the same APIs and predicates as | ||
:swift-sdk:`List\<Element\> <Classes/List.html>` and | ||
:swift-sdk:`Results\<Element\> <Structs/Results.html>`. |
66 changes: 66 additions & 0 deletions
66
source/includes/sdk-examples/crud/read-query-inverse-relationship.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.. tabs-drivers:: | ||
|
||
tabs: | ||
- id: cpp-sdk | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.cpp | ||
:language: cpp | ||
:copyable: false | ||
|
||
- id: csharp | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/dotnet/Relationships.snippet.inverse-query.cs | ||
:language: csharp | ||
|
||
- id: dart | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/flutter/backlinks_test.snippet.filter-backlinks-rql.dart | ||
:language: dart | ||
|
||
- id: java | ||
content: | | ||
|
||
.. include:: /examples/generated/java/sync/RealmQueryTest.snippet.query-an-inverse-relationship.java.rst | ||
|
||
- id: java-kotlin | ||
content: | | ||
|
||
.. include:: /examples/generated/java/sync/RealmQueryTest.snippet.query-an-inverse-relationship.kt.rst | ||
|
||
- id: javascript | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/node/v12/relationships.test.snippet.obtain-inverse-relationship-dynamically.js | ||
:language: javascript | ||
|
||
- id: kotlin | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.persisted-name-inverse.kt | ||
:language: kotlin | ||
:emphasize-lines: 1 | ||
|
||
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.query-inverse-persisted-name.kt | ||
:language: kotlin | ||
:emphasize-lines: 4 | ||
|
||
- id: objectivec | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/code/start/ReadWriteData.snippet.query-an-inverse-relationship.m | ||
:language: objectivec | ||
|
||
- id: swift | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.query-an-inverse-relationship.swift | ||
:language: swift | ||
|
||
- id: typescript | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/node/v12/relationships.test.snippet.obtain-inverse-relationship-dynamically.ts | ||
:language: typescript |
69 changes: 69 additions & 0 deletions
69
source/includes/sdk-examples/crud/read-query-to-many-relationship.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
.. tabs-drivers:: | ||
|
||
tabs: | ||
- id: cpp-sdk | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.cpp | ||
:language: cpp | ||
:copyable: false | ||
|
||
- id: csharp | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/dotnet/Relationships.snippet.one-to-many-query.cs | ||
:language: csharp | ||
|
||
- id: dart | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/flutter/data_types_test.snippet.realmlist-use.dart | ||
:language: dart | ||
|
||
- id: java | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/java/sync/RealmQueryTest.snippet.query-a-relationship.java | ||
:language: java | ||
:emphasize-lines: 16 | ||
|
||
- id: java-kotlin | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/java/sync/RealmQueryTest.snippet.query-a-relationship.kt | ||
:language: kotlin | ||
:emphasize-lines: 15 | ||
|
||
- id: javascript | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.js | ||
:language: javascript | ||
:copyable: false | ||
|
||
- id: kotlin | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.query-to-many-relationship.kt | ||
:language: kotlin | ||
|
||
- id: objectivec | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.m | ||
:language: objectivec | ||
:copyable: false | ||
|
||
- id: swift | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.swift | ||
:language: swift | ||
:copyable: false | ||
|
||
- id: typescript | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.ts | ||
:language: typescript | ||
:copyable: false |
70 changes: 70 additions & 0 deletions
70
source/includes/sdk-examples/crud/read-query-to-one-relationship.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
.. tabs-drivers:: | ||
|
||
tabs: | ||
- id: cpp-sdk | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.cpp | ||
:language: cpp | ||
:copyable: false | ||
|
||
- id: csharp | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/dotnet/Relationships.snippet.one-to-one-query.cs | ||
:language: csharp | ||
|
||
- id: dart | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.dart | ||
:language: dart | ||
:copyable: false | ||
|
||
- id: java | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/java/sync/RealmQueryTest.snippet.query-a-relationship.java | ||
:language: java | ||
:emphasize-lines: 16 | ||
|
||
- id: java-kotlin | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/java/sync/RealmQueryTest.snippet.query-a-relationship.kt | ||
:language: kotlin | ||
:emphasize-lines: 15 | ||
|
||
- id: javascript | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.js | ||
:language: javascript | ||
:copyable: false | ||
|
||
- id: kotlin | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.query-to-one-relationship.kt | ||
:language: kotlin | ||
|
||
- id: objectivec | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.m | ||
:language: objectivec | ||
:copyable: false | ||
|
||
- id: swift | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.swift | ||
:language: swift | ||
:copyable: false | ||
|
||
- id: typescript | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.ts | ||
:language: typescript | ||
:copyable: false |
Oops, something went wrong.