ActiveRecord Object Comparision

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

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.

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