This patch makes the HasManyThroughAssociation behave more consistently with the other AssociationCollection methods by delegating as much as possible to the AssociationCollection class.
The detailed implications of this follow:
- :before_remove callbacks now get called for unsaved associates during .collection.delete() (for both HasManyThroughAssociation and HasAndBelongsToManyAssociation)
- HasManyAssociation#build() has been moved to AssociationCollection#build() and AssociationCollection subclasses all defer to it. HasManyThroughAssociation#build() and HasAndBelongsToManyAssociation#build() call load_target before defering to super.
- HasManyThroughAssociation#reset() has been removed and will defer to the equivalent AssociationCollection#reset() instead.
- HasManyThroughAssociation#delete() and HasManyThroughAssociation#<<() have been removed and will defer to AssociationCollection, which in turn will use the newly added HasManyThroughAssociation#insert_record() and HasManyThroughAssociation#delete_records() protected methods.
- Because of this HasManyThroughAssociation#replace() now works consistently with the other AssociationCollections
- And in turn because of this the has_many macro will add writer methods for the association.
- Added check for attempting to associate or disassociate an item on a has_many :through association where the source reflection relates back to the owner via has_many (instead of the usual belongs_to).
- I felt that it's just a little too presumptuous to just guess what to do with the join model. The belongs_to scenario entails some guesswork as well, but since that case is basically the equivalent of has_and_belongs_to_many with a visible join model it seems quite save to just assume the same behaviour as has_and_belongs_to_many.
- Added test cases for new functionality (I would have liked to do a more thorough job with this but I think that would require a pretty major overhaul of the active record tests)
- Removed test cases which ensured the previously non-existing features would be caught early (like .collection_ids= not being defined for HasManyThrough)