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
How to replaceById/replaceOrCreate with HasManyRepository #2273
Comments
From what I remember, we have intentionally left out In order to do a full replace of all properties, the caller must provide both the foreignKey value and the primary key ( Having said that, it's possible we are missing something and there are reasons why our proposal does not work well in practice. Let's discuss! Also, there are two possible PUT endpoints we may want to expose:
|
@bajtos thanks for your detailled answer.
This make a lot of sense. I've adjusted my code to use the right repository and it works just perfectly. Side note, in my usecase (mimicing an "include") I don't have (and I don't want) an extra endpoint to update a "subresource". closing |
Awesome! I am glad my advice worked for you. I think you are not the last person encountering this question. Could you advise us how to improve the documentation so that the next person will find the information right in the docs and don't have to go to our issue tracker? Where would you (did you?) look? Would you mind to contribute this improvement yourself? See https://loopback.io/doc/en/contrib/doc-contrib.html to get started. I am re-opening this issue and labelling it as "docs". |
@bajtos second thought on that one. I still thing the doc for updating is fine in some cases but then came one of the cases you mentioned:
I think this one makes a lot of sense as well (and there's a case in the // something like
replaceById(pk, fk, model) If I'm using the above mentioned end-point using the target model repository to do an update, it's super easy to mess up with the foreign key thoughts ? |
@ludohenin sorry for a late response, I have too many GitHub notifications to keep up with them :(
I was not able to find the place in our todo-list example using this endpoint, could you please post a link to the code you are referring to?
I am not sure if all LB4 users will see it the same way and consider the FK value provided in the URI as the source of truth. I think this can create a confusing situation for callers, when they edit the FK in the request body and but don't see the changes being made in the database. I guess it would make sense to me if the operation required both FK values to be identical, and aborting the request with a descriptive error otherwise.
It's not clear to me why it's super easy to mess up the foreign key, could you please post your code so that I can better understand what you have tried so far? To avoid confusion: I am not entirely against implementing |
@bajtos Sorry (as well) for the very late reply
You got it all here. Would be really nice to have this consistency check. |
Description / Steps to reproduce / Feature proposal
While trying to implement an array inclusion in model property defined as
HasMany
I realized thatHasManyRepository
is missing aput
method. Thepatch
is not enough as it does not allow to have the foreign key set in the model (throwing an errorProperty myModelId cannot be changed!
).Current Behavior
HasManyRepository implements:
Expected Behavior
HasManyRepository should implement:
The text was updated successfully, but these errors were encountered: