# Composed\_of, aggregate object isn't saved

**URL:** <https://www.ruby-forum.com/t/composed-of-aggregate-object-isnt-saved/161487>\
**Category:** Rails\
**Created:** [February 26, 2009, 10:01pm UTC](https://www.ruby-forum.com/t/composed-of-aggregate-object-isnt-saved/161487 "2009-02-26T22:01:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [February 26, 2009, 10:01pm UTC](https://www.ruby-forum.com/t/composed-of-aggregate-object-isnt-saved/161487/1 "2009-02-26T22:01:00Z")

</div>

I am relatively new to rails and I cannot figure out what is going on  
here. I am using the composed\_of method in an ActiveRecord class to  
create two aggregate properties: shipping\_address and billing\_address.  
The object properties are getting populated from the form and validation  
is working - no problem. When I call order.save, though, everything is  
being saved except the address fields. I am not getting any errors - it  
is just that none of the address info is saved to the database. I even  
ran script/console and manually created and saved an order there - same  
result.

Anyone have any ideas? Below is the Order class. Thanks.

class Order \< ActiveRecord::Base  
belongs\_to :payment\_type  
has\_many :line\_items, :dependent =\> :delete\_all

composed\_of :shipping\_address,  
:class\_name =\> ‘Address’,  
:mapping =\>  
[  
%w(street, street),  
%w(street2, street2),  
%w(city, city),  
%w(state, state),  
%w(zip, zip)  
] do |p|  
Address.new p[:street], p[:street2], p[:city], p[:state], p[:zip]  
end

composed\_of :billing\_address,  
:class\_name =\> ‘Address’,  
:mapping =\>  
[  
%w(billing\_street, street),  
%w(billing\_street2, street2),  
%w(billing\_city, city),  
%w(billing\_state, state),  
%w(billing\_zip, zip)  
] do |p|  
Address.new p[:street], p[:street2], p[:city], p[:state], p[:zip]  
end

…

end

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [February 26, 2009, 10:21pm UTC](https://www.ruby-forum.com/t/composed-of-aggregate-object-isnt-saved/161487/2 "2009-02-26T22:21:14Z")

</div>

Oh, forgot: I’m running rails 2.2.2, mysql 5.0.45, OSX

and here is the address class

class Address  
attr\_reader :street, :street2, :city, :state, :zip

def initialize(street, street2, city, state, zip)  
@street = street  
@street2 = street2  
@city = city  
@state = state  
@zip = zip  
end

end
