-
Notifications
You must be signed in to change notification settings - Fork 84
Check for inverse_of in manually defined associations #193
Comments
As a matter of reporting, we can see what the bullet gem does, and do something similar. |
@ronen I've started some work with schema_association_inverses (name suggestions welcome...). That requires a PR from schema_monkey, but is essentially just raising an error when an inverse cannot be detected for now. I absolutely cannot write specs for it because my development machines are all running Windows -- any way to get the build matrix working on it? |
@lowjoel cool
maybe something like...?
Is that likely to break things for core rails or 3rd-party gems that rely on lack of inverse failing quietly? Should this add support for something like
Looks good, go ahead and issue the PR! BTW see also SchemaPlus/schema_monkey#1
Hmm, I've never done any ruby development on Windows. I have no idea what it would take to get ...or can you run linux in a VirtualBox on Windows and do your development in that...? |
I think
I think we can preliminarily implement throwing an error first, once we have all the boilerplate up, we can start implementing nicer error displays (like how Bullet does it)
I could, but I'm afraid I'll have to push the stuff out without specs for now. RVM on Windows is a royal pain. I have a VM for things like these, but it's annoying to maintain separate environments... I'll try to see if I can get the test infra working on Windows then.
Yup. As a whole Ruby on Windows is fine. What works on Linux tends to work just fine on Windows, unless a native extension is involved... |
Actually you can run tests without
...or whatever the equivalent is in windows? I've been thinking of adding an option to |
@ronen sorry I've been too busy lately. I just upgraded my gem to use the schema_plus_core gem (since that's where all the hooks are defined). I'm going to give a shot at making the tests run. |
@ronen So to this end, I've submitted SchemaPlus/schema_plus_core#1 to implement the hook needed for this gem. I've manually set up schema_dev in lowjoel/schema_plus_association_inverses@d5fdff3b2c and got the first test up and running. Let me know what you think. |
Guys, I've released lowjoel/schema_plus_association_inverses@5574f33 |
Rails 4 added the
inverse_of
option when defininghas_one
andhas_many
relationships. It then does heuristics to determine the inverse of the relation, but does not warn when the inverse cannot be found.inverse_of
is necessary for proper behaviour in the following scenario: Assuming two modelsA
andB
, with instancesa
andb
, and code likea.b.a.b.a
would to be identical toa
. We tend to expect this but if inverses are not properly set we will get 3 different A instances created.In my opinion, adding a warning when ActiveRecord fails to find an association would be sufficient, but more adventurous contributors might want to add a rake task or some sort of validation that can be run in a CI build.
Of course, @ronen and I think that using the schema_associations gem is the best since that defines the inverses automatically, but for the rest of us who do not...
The text was updated successfully, but these errors were encountered: