Hi All, I have a active record object(FIRST) with some attributes. I have another activerecord object(SECOND) with different attributes. I want to compare those two active record objects whether they have equal values in every field or not. I tried like actual.attributes == existing.attributes But this one is related to same attribute names, But i have different attribute names in activerecord objects. Could you help me in this. I was struck with this issue. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 5, 10:03 am, merbivore <eshward...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > > I have a active record object(FIRST) with some attributes. I have > another activerecord object(SECOND) with different attributes. > > I want to compare those two active record objects whether they have > equal values in every field or not. > > I tried like > actual.attributes == existing.attributes > > But this one is related to same attribute names, But i have different > attribute names in activerecord objects. > > Could you help me in this. I was struck with this issue.So what is your definition of == ? are attribute names completely irrelevant or is there a mapping of some sort. If you really are just interested in the values of the fields blah.attributes.values will give you that (you probably want to omit the id attribute from that). Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Fred, Thanks for the quick reply. My first activerecord object is {"BaseManagedEntityInternalId"=>17, "BaseManagedEntityId"=>"37532278-43C5-411F-593E-96B1A74C6B18", " NetworkName"=>"rocscom.roc.com", "IPAddress"=>"172.16.1.100, fe80::7805:44c6:9da9:9d01"} My Second activerecord object is {"location"=>nil, "created_at"=>Tue Aug 30 12:01:25 UTC 2011, "updated_at"=>Tue Aug 30 12:01:25 UTC 2011, "contact"=>nil, "id"=>1, "os_name"=>"", "os_version"=>"", "device_ip"=>"172.16.1.100, fe80::78 05:44c6:9da9:9d01", "basemanged_internal_id"=>17, "device_name"=>"rocscom.roc.com", "basemanged_enti ty_id"=>"37532278-43C5-411F-593E-96B1A74C6B18"} I want to compare these two objects for specific fields like ipaddress, device_name like that. Could you help me now plz. On Sep 5, 2:32 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 5, 10:03 am, merbivore <eshward...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi All, > > > I have a active record object(FIRST) with some attributes. I have > > another activerecord object(SECOND) with different attributes. > > > I want to compare those two active record objects whether they have > > equal values in every field or not. > > > I tried like > > actual.attributes == existing.attributes > > > But this one is related to same attribute names, But i have different > > attribute names in activerecord objects. > > > Could you help me in this. I was struck with this issue. > > So what is your definition of == ? are attribute names completely > irrelevant or is there a mapping of some sort. If you really are just > interested in the values of the fields blah.attributes.values will > give you that (you probably want to omit the id attribute from that). > > Fred-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 5, 10:47 am, merbivore <eshward...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Fred, > > Thanks for the quick reply. > > My first activerecord object is > > {"BaseManagedEntityInternalId"=>17, > "BaseManagedEntityId"=>"37532278-43C5-411F-593E-96B1A74C6B18", " > NetworkName"=>"rocscom.roc.com", "IPAddress"=>"172.16.1.100, > fe80::7805:44c6:9da9:9d01"} > > My Second activerecord object is > > {"location"=>nil, "created_at"=>Tue Aug 30 12:01:25 UTC 2011, > "updated_at"=>Tue Aug 30 12:01:25 UTC > 2011, "contact"=>nil, "id"=>1, "os_name"=>"", "os_version"=>"", > "device_ip"=>"172.16.1.100, fe80::78 > 05:44c6:9da9:9d01", "basemanged_internal_id"=>17, > "device_name"=>"rocscom.roc.com", "basemanged_enti > ty_id"=>"37532278-43C5-411F-593E-96B1A74C6B18"} > > I want to compare these two objects for specific fields like > ipaddress, device_name like that. >well it does look like you''d have to explicitly write out the comparison you want to make, e.g. first.device_ip == other.IPAddress && first. basemanged_entity_id =other.BaseManagedEntityId Fred> Could you help me now plz. > > On Sep 5, 2:32 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > > > On Sep 5, 10:03 am, merbivore <eshward...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi All, > > > > I have a active record object(FIRST) with some attributes. I have > > > another activerecord object(SECOND) with different attributes. > > > > I want to compare those two active record objects whether they have > > > equal values in every field or not. > > > > I tried like > > > actual.attributes == existing.attributes > > > > But this one is related to same attribute names, But i have different > > > attribute names in activerecord objects. > > > > Could you help me in this. I was struck with this issue. > > > So what is your definition of == ? are attribute names completely > > irrelevant or is there a mapping of some sort. If you really are just > > interested in the values of the fields blah.attributes.values will > > give you that (you probably want to omit the id attribute from that). > > > Fred-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.