-
Notifications
You must be signed in to change notification settings - Fork 41
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
before_validation :update_permalink, on: :create is never triggered in an hyper model #218
Comments
Interesting. Thanks for the report and investigation |
The problem is that when saves are done from the client, hyperstack has to first "recreate" the context of all the records on the client. In some cases you can have validations that require some relationship exist, but these same relationships are already on the client. Hence we first save everything without validations, then roll back any things that are not true saves, then finally run the validations. In looking into Rails validations, it appears we might be able to force If you are interested in helping out, you could do a little sandbox experiment for us: Try saving one of your records and then running In the meantime do you need a work around? I would suggest that you could use a ServerOp to do the save would be the best workaround. |
Client/server synchronization is an hard problem.
I am sorry, I am currently on vacation. I will do that after the 19.
I prefer a durable solution. I think we should write some tests. |
Sorry this was unclear. You are exactly right, all validations must be done on the server. So before doing any validations, we have to make sure that the current set of changes on the client are recreated on the server.
No rush, it will be great to have help!
Really glad to hear that. With very few exceptions all changes to the code base come with tests, so creating the test specs is a good first step, or at least in parallel with seeking a solution! |
In another project I designed a complex form system. I think I had a similar problem and I solved it this way:
Save a record without validation (like in hyperstack) should be done only when it is needed to break a dependency cycle. In most of the case it is not necessary. Did you try something like that instead of save records twice ? |
If I understand you, this is close to what Hyperstack is doing, however to keep the programmer from doing extra work it has to do it in a general way without specific application knowledge. (I think you agree with that correct?) As you point out the problem is cyclical dependencies requiring save's to be done first, and then validations. I have no problem if you want to try to rewrite that core algorithm (it is in need of refactoring for sure) to use your approach. HOWEVER...I would add this caution:
Soooo... For now I would suggest getting the problem fixed by going after the on: :create simulation, and we can add another issue to do the bigger cleanup later. |
…k, on: :create is never triggered in an hyper model
…: :create is never triggered in an hyper model
fix issue #218: before_validation :update_permalink, on: :create is n…
This is a common pattern to initialize some attributes before validation on creation. For instance acts_as_permalink does that: https://github.com/kmcphillips/acts_as_permalink/blob/55e824a5bf76f30ce8250dd9438bc46234e25b45/lib/concern.rb#L10
But in hyperstack, a new_record is saved without validation and validated later:
hyperstack/ruby/hyper-model/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb
Line 499 in bf2fa76
The callback is never triggered because validation is applied to a record that is already created.
The text was updated successfully, but these errors were encountered: