Skygear supports many-to-one (aka. parent-child) relation between records via reference.
SKYReference is a pointer to a record in database. Let's say we are going to
reference Record A in Record B, we first construct a reference of Record A
using its id.
Then assign this reference as a regular field of Record B:
It will establish a reference from Record B to Record A.
Querying referenced records
This example shows how to query all notes (
Note record) who has an
account field reference to a user record. In this example, we will query all notes where
account equals to the current user.
Relational query by fields of reference record
You can query by fields on a referenced record. Following the above example, if we want to query all notes where account's role is editor only:
Relational query by record's ID
If you haven't have the corresponding record in hand (in this example, we will use the User record
182654c9-d205-43aa-8e74-d465c830087a), you can reference with a specify
id without making another query in this way:
Skygear support eager loading of referenced records when you are querying the
referencing records. It's done by supplying a key path expression to
It is possible to eager load records from multiple keys, but doing so will impair performance.
Deleting referenced records
ON DELETE CASCADE TBC.