-
Notifications
You must be signed in to change notification settings - Fork 366
Fix #481 and #474 #483
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
Fix #481 and #474 #483
Conversation
LGTM. @bajtos PTAL. |
I am very strongly opposed to this change, see #474 (comment) and #481 (comment). |
@bajtos I will adapt the unit tests - this is a critical flaw that needed to be addressed, so I disagree completely with your strong rejection. |
@fabien have you read my comments in the other two issues? Your pull request is a hack fixing the wrong thing in my opinion. I really don't want to end up in the same situation as we have with the old model hooks, where it was not possible to fix them and I had to rewrite them from scratch. Please don't work on this pull request until we come to an agreement on what's the right way how to address your problem, as otherwise you may just waste your time. In case I did not make myself clear, I truly want to improve the operations hooks to serve your use case. At the same time, I want to find a solution that will not compromise the current design, will not add even more confusion and will not make the future maintenance more difficult. For example, the question of using "this" vs. "data" is a commonly asked question about the old hooks and I really don't want to introduce the issue back into the new hooks. |
@bajtos yes, I read your comments, and I can see what you mean. However, I don't think this PR is moving in the wrong way, it just needs to be fleshed out. Let's go ahead constructively. Let me remind you that the current working state of operation hooks simply cannot do what the old First of all, can we agree on: Any hook operating on an instance-level should also receive the instance in the context. I agree, at the moment the PR is incomplete, because it doesn't handle the If an instance is passed in the context, it should never be used to manipulate data - it is only there to get the current state (for comparison for example). Any changes would go into the |
This is what I disagree with. One of the ideas behind ORM and OOP in general is that the objects should encapsulate the behaviour and hide implementation details. An example is a property with custom setter that creates a normalised version of the input value, or a prototype method that performs some calculation and updates several properties. Another example is a code that changes some model properties and then would like to get a value computed from these changed properties. That's why I believe users should use the instance object to manipulate the data in as many places as possible. Because if they had only the Also because we perform a validation of the updated model instance, in many cases we would have to 1) extract data from the instance before calling the hooks, 2) pass the data back to the instance for validation. At the moment, we can skip 1) because hooks are manipulating the instance directly.
There are two basic ways how the hook may want to use the instance: A) It wants to modify the data that will be persisted to the database, this is specific to "before save" hook. We must make it very clear whether the save will update the whole record ( B) It wants to get more information about the model instance affected. IIRC, there are only two cases where we are not exposing this data even though we have it available: Let's focus at When it comes to My conclusion is that we need to come up with a new property name that will be set in the where+data case and that will make it very clear that the changes made to this instance will be ignored by the operation. Perhaps Thoughts? I'd like to hear @raymondfeng and @ritch opinion too. |
@bajtos this is another way to look at it, but it is fine with me, as long as we make a clear distinction. From what I've learned during refactoring to operation hooks, it is indeed just the Say we'd go with |
My concern is that converting the instance to data is not free, it takes some time and allocates extra memory. I don't want all users to pay this price. Can we come up with a better name that would make the intent more clear than |
What about |
Sounds good too. Let's go with |
@bajtos will Currently, in |
Closing this in favor of #486 |
http://docs.strongloop.com/display/public/LB/Operation+hooks will need updates