# Ticket #11394, Adding ActiveRecord::Errors#merge! method

**URL:** <https://discuss.rubyonrails.org/t/ticket-11394-adding-activerecord-errors-merge-method/26947>\
**Category:** rubyonrails-talk\
**Created:** [March 27, 2008, 2:11pm UTC](https://discuss.rubyonrails.org/t/ticket-11394-adding-activerecord-errors-merge-method/26947 "2008-03-27T14:11:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zdennis](https://avatars.discourse-cdn.com/v4/letter/z/d78d45/32.png) [@zdennis](https://discuss.rubyonrails.org/u/zdennis)\
**Post date:** [March 27, 2008, 2:11pm UTC](https://discuss.rubyonrails.org/t/ticket-11394-adding-activerecord-errors-merge-method/26947/1 "2008-03-27T14:11:28Z")

</div>

Ticket 11394 adds the merge! method to any ActiveRecord::Errors object. If anyone has time to review the ticket and post their comments on if they like the idea of having this functionality:

[http://dev.rubyonrails.org/ticket/11394](http://dev.rubyonrails.org/ticket/11394)

Examples: &nbsp;&nbsp;&nbsp;person.errors.merge address.errors &nbsp;&nbsp;&nbsp;person.errors.merge address.errors, :only =\> [:city, ;state] &nbsp;&nbsp;&nbsp;person.errors.merge address.errors, :except =\> [:street, :zip]

Thanks,

Zach Dennis [http://www.continuousthinking.com](http://www.continuousthinking.com)

---

<div class="post-metadata">

**Author:** ![zdennis](https://avatars.discourse-cdn.com/v4/letter/z/d78d45/32.png) [@zdennis](https://discuss.rubyonrails.org/u/zdennis)\
**Post date:** [March 27, 2008, 2:13pm UTC](https://discuss.rubyonrails.org/t/ticket-11394-adding-activerecord-errors-merge-method/26947/2 "2008-03-27T14:13:25Z")

</div>

Those examples should be "merge!" and not "merge"

Zach Dennis [http://www.continuousthinking.com](http://www.continuousthinking.com)

---

<div class="post-metadata">

**Author:** ![AndyV1](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@AndyV1](https://discuss.rubyonrails.org/u/AndyV1)\
**Post date:** [March 27, 2008, 3:13pm UTC](https://discuss.rubyonrails.org/t/ticket-11394-adding-activerecord-errors-merge-method/26947/3 "2008-03-27T15:13:58Z")

</div>

I think the example is too contrived. That particular situation you would/could solve using errors\_for 'person', 'address'. A better example would be something that uses delegation.

class ZipCode \< ARec::Base &nbsp;&nbsp;has\_many :addresses &nbsp;&nbsp;validates\_presence\_of :city, :state, :zip end

class Address \< ARec::Base &nbsp;&nbsp;belongs\_to :zip\_code &nbsp;&nbsp;validates\_presence\_of :street &nbsp;&nbsp;validates\_associated :zip\_code

&nbsp;&nbsp;[:city, :state, :zip].each do |delegated\_attribute| &nbsp;&nbsp;&nbsp;&nbsp;delegate delegated\_attribute, "#{delegated\_attribute}=", :to=\>:zip\_code &nbsp;&nbsp;end

&nbsp;&nbsp;def initialize(\*attrs) &nbsp;&nbsp;&nbsp;&nbsp;params = attrs.last.is\_a?(Hash) ? attrs.last : {} &nbsp;&nbsp;&nbsp;&nbsp;self.zip\_code = params[:zip\_code\_id].nil? ? ZipCode.new : ZipCode.find(params[:zip\_code\_id]) &nbsp;&nbsp;&nbsp;&nbsp;super &nbsp;&nbsp;end end

home = Address.new :street=\>'123 Main St', :city=\>'Anytown', :state=\>'SC' home.valid? #=\> false

In this scenario it would be helpful to merge the errors from home and home.zip\_code since they appear to be one object to the user.
