It would be nice to add a method to the association proxy named the same way as the inverse_of option which allows traversal back to the owner object.
class Alphabet < ActiveRecord::Base
has_many :letters, inverse_of: :alphabet
class Letters < ActiveRecord::Base
letters = Alphabet.first.letters
letters.alphabet #Return the alphabet object
This can currently be done by doing the following:
class Alphabet < ActiveRecord::Base has_many :letters, inverse_of: :alphabet do def alphabet proxy_association.owner end end
I guess it’s not so hard to define this manually every time, but it would be a neat way to save some code, especially for occasions when you pass in a association (say to a view or authorisation object) and you want to get back the owner.