1

According to API Dock, ActiveRecord::Associations::AssociationProxy is now "deprecated or moved". I'm curious as to what happened to this class. If it really no longer exists, how does Rails now handle associations? According to several other posts on this site (like this one), AssociationProxy is necessary for allowing syntax such as User.find(1).groups << Group.find_by_id(13).

Community
  • 1
  • 1
Ajedi32
  • 45,670
  • 22
  • 127
  • 172

1 Answers1

2

According to the ActiveRecord's changelog for the version 3.1.0:

  • ActiveRecord::Associations::AssociationProxy has been split. There is now an Association class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called CollectionProxy, which proxies collection associations.

    This prevents namespace pollution, separates concerns, and will allow further refactorings.

    Singular associations (has_one, belongs_to) no longer have a proxy at all. They simply return the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead.

jdoe
  • 15,665
  • 2
  • 46
  • 48
  • Ah, the changelog. That sounds like it might be useful in the future. Would you happen to know where I can find the rest of the Rails changelog? – Ajedi32 Sep 10 '12 at 19:25
  • 1
    @Ajedi32 Well known Ruby on Rails Guides contain this info. Goto http://guides.rubyonrails.org/, scroll to the almost bottom (to the section called "Release Notes"), enjoy. E.g., here's changes for the 3.1 release: http://guides.rubyonrails.org/3_1_release_notes.html. – jdoe Sep 10 '12 at 19:33