themetalfleece / neogma

Object-Graph-Mapping neo4j framework, Fully-typed with TypeScript, for easy and flexible node and relationship operations
https://themetalfleece.github.io/neogma/
MIT License
124 stars 12 forks source link

Return information indicating whether update of relationship was successfull #37

Closed JonasHiltl closed 3 years ago

JonasHiltl commented 3 years ago

When updating a relationship with the updateRelationship method either through an instance or the model itself it is not possible to know if the update was successfull or if for example the target was icorrect. I tried updating the relationship of a user with the function below and I could not find a value on the result object that indicated if the update was successfull. For me the records array in the result was always an empty list even when the update was successfull. The updateStatistics also did not change between an update that changed the relationship and an update that did not change anything. Is it possible to return the number of updates that got executed so that we can decide if the update was successfull?

const result = await User.updateRelationship(
  { accepted: false },
  {
    alias: "Friend",
    where: {
      source: {
        id: req.user?.id.trim()!,
      },
      target: {
        id: req.params.id.trim(),
      },
      relationship: {
        accepted: true,
      },
    },
  }
);
themetalfleece commented 3 years ago

updateRelationship returns the query result as is (from the neo4j driver), so there is nothing that Neogma can generate that isn't already there.

Does the following have any useful information?

console.log(result.summary.counters.updates());
JonasHiltl commented 3 years ago

propertiesSet returns the number of properties that got updated. I will use that to determine if the update was successfull. Thanks a lot