I read about inverse_of, and everything I see on the Internet seems inconsistent and confuses me. If you look here , you can see
There are several limitations to supporting inverse_of:
- They do not work with: through associations.
- They do not work with: polymorphic associations.
- They do not work with: as associations.
- For belongs_to associations, the reverse has_many associations are ignored.
but right above that, they give this example
class Customer < ActiveRecord::Base has_many :orders, :inverse_of => :customer end class Order < ActiveRecord::Base belongs_to :customer, :inverse_of => :orders end
I think they say that the first inverse_of does nothing, but if so, why did they do it?
Also, while the above says inverse_of doesn't work through associations, this page says
If you use role_to in the connection model, it is recommended to set the option: inverse_of> to role_to, which will mean that the following example works correctly, where> tags is has_many: through union):
and gives this example
@post = Post.first @tag = @post.tags.build :name => "ruby" @tag.save
The last line should save the recorded record (Taggable). This will only work if set to>: inverse_of:
class Taggable < ActiveRecord::Base belongs_to :post belongs_to :tag, :inverse_of => :taggings end
It all seems inconsistent and very confusing to me. But in general, I see no harm, just saying the opposite in all respects. This is problem? I saw how many people ask about it, and have not seen a single solid yes or no.
bdwain
source share