ruby on rails - How to merge two instance of a Model like hashes -
i can merge 2 hashes this:
array = [{a: 1, b: 2, c: 3}, {a:3, b:1, d:5}] array[0].merge(array[1]) |k, v1, v2| [v1, v2].compact.max end
and want merge 2 activerecord::base
instances , create new one. activerecord::base
class doesn't have merge
method.
how can merge 2 instances of rails model , create new instance?
activerecord::base#attributes
returns hash. these hashes can merge values of rails model instances.
Comments
Post a Comment