It looks like association extensions have changed quite a bit throughout Rails 3.x.
I need to access the proxy owner and the proxy target (i.e, the has_many object and the belongs_to object).
The most recent documentation says To use proxy_association.owner and proxy_association.target. However, this throws an method missing. I found some older references (can’t find them now), saying that self.proxy_target would work. However this only seems to work intermittently and isn’t reliable between my local environment and production (strange… I know).
Does anybody know where I can find more definitive answer on how to access the owner and target from within an association extension using Rails 3.0.10?
proxy_associationis new in rails 3.1. The rails 3.0.x (and 2.x) equivalent isproxy_ownerandproxy_target. Howeverproxy_targetreturns the instance variable that caches the association if it has been loaded, i.e. if the association has not yet been loaded you’d get back[]for a collection association. Or in other words, giventhen
You can force the target to be loaded by calling
load_targetbefore callingproxy_target. That all set I’m not sure why this is important – if you call stuff onselfit will be forwarded to the target for you