joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-04 20:59 UTC
belongs_to question
Okay. class User < AR belongs_to :address end class Address < AR has_one :user end So far, so good. But, now each user can have two addresses. class User < AR belongs_to :default_billing_address, :class => Address belongs_to :default_shipping_address, :class => Address end And I added default_billing_address_id and default_shipping_address_id to the User table. But it doesn''t seem to be working properly. I can: u = User.find(x) u.default_billing_address = Address.find(y) u.save But the default_billing_address_id field is never changed. Any ideas? Thanks, Joe --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi! Try this: class User < AR belongs_to :default_billing_address, :class => Address, :foreign_key => "default_billing_address_id" belongs_to :default_shipping_address, :class => Address, :foreign_key => "default_shipping_address_id" end I think Rails supposes both adresses to be referenced with address_id. Hope this helps, Markus On 10/4/06, joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Okay. > > class User < AR > belongs_to :address > end > > class Address < AR > has_one :user > end > > So far, so good. But, now each user can have two addresses. > > class User < AR > belongs_to :default_billing_address, :class => Address > belongs_to :default_shipping_address, :class => Address > end > > And I added default_billing_address_id and default_shipping_address_id > to the User table. But it doesn''t seem to be working properly. I can: > > u = User.find(x) > u.default_billing_address = Address.find(y) > u.save > > But the default_billing_address_id field is never changed. Any ideas? > > Thanks, > Joe > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---