Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationships are not included in result of relationship add method #1403

Open
JF-Cozy opened this issue Oct 16, 2023 · 3 comments
Open

Relationships are not included in result of relationship add method #1403

JF-Cozy opened this issue Oct 16, 2023 · 3 comments

Comments

@JF-Cozy
Copy link
Contributor

JF-Cozy commented Oct 16, 2023

When you create a relationship between 2 doctypes, for example io.cozy.geojson.timeseries and io.cozy.contacts to have a contact in a timeseries, it is then possible to use an add method on the relationship from the timeseries timeserie.myRelation.add().

This method updates the timeserie document and returns this new object with its new revision. The problem is that if the app includes the relationships in the reference document (timeserie in this example), the document returned by the add() method does not have these includes.

@Crash--
Copy link
Contributor

Crash-- commented Oct 16, 2023

Can you provide code sample? Schema and how you make the call please?

Also, I though we should not use .add anymore but use instead the static helper. 🤔

@JF-Cozy
Copy link
Contributor Author

JF-Cozy commented Oct 17, 2023

Schema de Client :

timeseries: {
  doctype: GEOJSON_DOCTYPE,
  attributes: {},
  relationships: {
    startPlaceContact: {
      type: 'has-one',
      doctype: CONTACTS_DOCTYPE
    }
  }
}

La requête (simplifiée) afin d'include les relationships :

Q(GEOJSON_DOCTYPE).include(['startPlaceContact'])

A partir de là, j'ai donc dans mon doc timeserie un attribut startPlaceContact dans lequel se trouve le contact associé.

Puis j'ajoute une relation :

const { data: res } = await timeserie.startPlaceContact.add(someContact)

Or cet attribut startPlaceContact n'existe plus dans l'object res retourné.

A noter que si j'ai besoin de startPlaceContact il faut que je le récupère du timeserie initial mais sans l'ajouter à res, car si j'ai besoin ensuite de client.save(res) (par exemple parce que je rajoute des metadata à la relation, voir #1393) le save se fait mal si j'ai ajouté startPlaceContact à l'objet. Autre souci, je ne peux pas client.save(timeserie) puisqu'en faisant await timeserie.startPlaceContact.add(someContact) la rev du doc change, c'est donc bien res qu'il faut ensuite manipuler.

@Merkur39
Copy link
Member

Pour clarifier, ce comportement est "normal" puisque que le document retourner est le retour de la méthode save de CC qui n'hydrate pas le document.
Je suppose qu'un client.hydrateDocument solutionne ce problème.

Pour ce qui est des méthodes statiques, je crois qu'elles n'existe que côté HasMany

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants