Joshua M. wrote:
I want to overwrite the push method (which is an alias of <<, the same
as concat) of collections, and there I want to test if :uniq is set to
true in the relationship. If so, the method should check if the passed
object is already related to the parent, or not (only then it will be
But I just can’t find the original code of this method, so I could
overwrite it… Can anyone tell me? Thanks.
class AssociationCollection < AssociationProxy #:nodoc:
result = true
flatten_deeper(records).each do |record|
result &&= insert_record(record) unless @owner.new_record?
@target << record
result and self
alias_method :push, :<<
But I’d think you’re better off not overriding that. Better to have a
wrapper method in the parent class.