Forum: Ruby on Rails Rails Guide:"For belongs_to associations, has_many inverse associations are ignored." not clear?

1fe9e3bb4c8fbe22e6956b2eb0a79798?d=identicon&s=25 Paul Leader (Guest)
on 2012-11-13 00:06
(Received via mailing list)
Perhaps I'm bing a bit thick and missing something obvious (possible),
but
I found the caveats listed in section 3.5 of the Associations Rails
Guide<http://guides.rubyonrails.org/association_basics.html> badly
worded and confusing.

The section gives an example with a has_many <-> belongs_to relationship
is
setup with inverse associations on both side, but then states the
caveat*"For belongs_to associations, has_many inverse associations are
ignored."
*

Could someone actually explain what that means in concrete terms? The
example and the caveat appear to be contradictory. If the caveat is
correct
then I'm not sure I understand how the example works.

Paul
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2012-11-13 05:18
(Received via mailing list)
On Mon, Nov 12, 2012 at 4:09 AM, Paul Leader <paul@paulleader.co.uk>
wrote:
> then I'm not sure I understand how the example works.
I've never needed :inverse_of.  Looks like academic masturbation to me.


--
Greg Donald
1fe9e3bb4c8fbe22e6956b2eb0a79798?d=identicon&s=25 Paul Leader (Guest)
on 2012-11-13 10:25
(Received via mailing list)
It is useful in a small number of situations, mostly where you need to
ensure that two different references to the same object actually refer
to
the same instance.  I've only needed to use it twice, both times were
where
we have callbacks updating multiple related objects based on data held
in
each other.

Anyway, if anyone else does understand what that caveat actually means
I'd
appreciate an explanation.
F748b501a4c680b574612f05b87bd284?d=identicon&s=25 gamov (Guest)
on 2013-10-09 10:07
(Received via mailing list)
I also don't understand what they mean since the example seems to
contradict it...
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2013-10-09 10:43
(Received via mailing list)
On 9 October 2013 09:05, gamov <gamaudruz@gmail.com> wrote:
> I also don't understand what they mean since the example seems to contradict
> it...

Exactly which bit of
http://guides.rubyonrails.org/association_basics.h...
seems to be a contradiction?  Unless you explain /exactly/ what you do
not understand it is difficult to help.

Colin
E6796c9279a72bdcb8331a3f2604472d?d=identicon&s=25 unknown (Guest)
on 2014-05-30 22:48
(Received via mailing list)
The example included says...

class Customer < ActiveRecord::Base
  has_many :orders, inverse_of: :customer
end

class Order < ActiveRecord::Base
  belongs_to :customer, inverse_of: :orders
end

---

Later on, the guid mentions...

There are a few limitations to inverse_of support:

   - 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, has_many inverse associations are
ignored.


El miércoles, 9 de octubre de 2013 03:42:11 UTC-5, Colin Law escribió:
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.