Closed urkle closed 5 years ago
@lowjoel can you re-review this? I redid the test to be a slightly more practical example. also I added documentation n the README and bumped the version to 1.3.0
@lowjoel @ronen this is blocking some other work that needs this update.. Can I get one of you to look over this and approve the changes I made?
Sorry for the delay, I don't have a good Internet connection these few days. Please send a chaser if you need sooner feedback.
I'm in two minds on this. On one hand this defines a new macro that really shouldn't be needed. I think we should probably override has_many
to look for through:
and figure out that we have to defer it automatically at the end of the process.
On the other hand that proposal is rather magical. Having said that, the point of schema associations is to be DRY, so... thoughts?
The first idea can be implemented by just recording all has_many through:
and running those at the end of defining all automatic schemas, much like how you've defined post_block
(call the new variable _deferred_associations
or something.) I should've thought about this when doing the initial review, sorry.
@lowjoel hmm.. that actually sounds like a good idea.. Though really I should be able to just do it with ALL associations that are defined (and some magic to prevent looping). I'll make a fixup w/ that approach and throw it to you.
@lowjoel I pushed up fixups that rework the behavior to be deferred for has_many and has_one (the only associations that support :through) I also backed down the version to 1.2.7 (instead of 1.3.0) since this does not change any public contracts now.
@lowjoel thanks for the review.. I've made adjustments as you requested.
@lowjoel this should be good now. everything is passing and there is no longer any contract change
Awesome, thanks!
I believe that the differences matter more for smaller classes, Ruby has a specialisation for classes with a small number of ivars, they transition to a hash table beyond a certain number. Not sure if remove_instance_variable
will even cause a reverse transition.
Having said that AR objects have a gazillion ivars, so... 🤷♂️ but it's good we thought about it.
In rails 5.1+ has any through associations have to reference an association defined BEFORE them.. Thus w/ Schema_associations we need to allow defining these manual associations after schema+ has defined the automatic ones.