Skip to content

Commit

Permalink
docs: Add metadata in relationships doc
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Oct 2, 2023
1 parent 1be3ded commit 1ee586f
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions docs/relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Cozy-Client [predefines](https://github.com/cozy/cozy-client/blob/master/package

#### Files relations

The files implements a special type of relation: `'io.cozy.files:has-many'`. This relation name is `referenced_by`, which is an array of references, just like the `'has-many'` relation.
The files implements a special type of relation: `'io.cozy.files:has-many'`. This relation name is `referenced_by`, which is an array of references, just like the `'has-many'` relation.

The stack implements routes to handle this kind of relation on the `/files` endpoint. See the [stack documentation](https://docs.cozy.io/en/cozy-stack/references-docs-in-vfs/).

Expand All @@ -77,7 +77,7 @@ You are free to create your own relation type if you need a special behaviour.

For instance, [Banks doctypes](https://github.com/cozy/cozy-banks/blob/master/src/doctypes.js) implements `HasManyBills` or `HasManyReimbursements`.

#### Old relation types
#### Old relation types

Note there are two others basic relations, that are here for backward compatibility:

Expand Down Expand Up @@ -110,6 +110,25 @@ const book = {
}
```

### Metadata

It is possible to assign metadatas to relationships. You need to modify the content of the document relationships somehow and save the modified document.

```javascript
const doc = {
_id: "mobydick",
relationships: {
authors: {
data: [{
_id: "hermanmelville",
_type: "io.cozy.contacts"
}]
}
}
}
doc.relationships.authors.data[0].metadata = { addressId: "123" }
await client.save(doc)
```

## Usage

Expand All @@ -123,9 +142,9 @@ const query = Q('io.cozy.books')
.limitBy(20)
```

You will then find your relations under the `data` attribute:
You will then find your relations under the `data` attribute:

```javascript
```javascript
const response = await client.query(query)
const docs = response.data
const firstDoc = docs[0]
Expand Down

0 comments on commit 1ee586f

Please sign in to comment.