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

Should we allow deactivating unitOfWork on create, update or delete method #94

Closed
jdeniau opened this issue Nov 13, 2020 · 1 comment · Fixed by #140
Closed

Should we allow deactivating unitOfWork on create, update or delete method #94

jdeniau opened this issue Nov 13, 2020 · 1 comment · Fixed by #140

Comments

@jdeniau
Copy link
Member

jdeniau commented Nov 13, 2020

Currently, we can deactivate unitOfWork for a call on the client :

sdk.getRepository('foo')
  .withUnitOfWork(false)
  .findAll()

We voluntarily throw an exception on create, update and delete call to prevent this:

sdk.getRepository('foo')
  .withUnitOfWork(false)
  .create(someEntity) // this will throw an error

We made this decision as we are not quite sure what to do in this case. Feel free to add a comment to discuss this case in this issue.

@jdeniau
Copy link
Member Author

jdeniau commented Mar 5, 2024

Upgrading this issue with latest thoughts:

We might want to deactivate the unitOfWork when we don't care about the result of the create, update or delete method.

Imagine a call that does fetch a item:

const item = await repository.find(1, { fields: '@id,name,type' });

later, we do have a modal that allow to change the name, but we don't care about the return

await repository.update(item.set('name', 'new name'), { fields: '@id' });

The unitOfWork will register the data with only the @id.

If later call a "type changer":

await repository.update(item.set('type', 'new type'), { fields: '@id' });

The getDirtyData will return that only the @id is known, and then send a call with:

{
  name: 'new name',
  type: 'new type',
}

We might want to disable the unit of work when "updating", as we do disable it for find method (a put is "just" a get that change some data before).

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

Successfully merging a pull request may close this issue.

1 participant