Sergio Bayona
2006-Apr-08 06:25 UTC
[Rails] saving related objects using has_many_through associations
This only saves the @person but not the @address. Shouldn''t it save both? @person = Person.new(params[:person]) @address = Address.new(params[:address]) @person.address << @address @person.save here is what I have: class Person < ActiveRecord::Base has_many :addressables has_many :addresses, :through => :addressables end class Address < ActiveRecord::Base has_many :addressables has_many :people, :through => :addressables end class Addressable < ActiveRecord::Base belongs_to :address belongs_to :person end Any help would be appreciated, Thanks Serge
Mark Reginald James
2006-Apr-10 13:02 UTC
[Rails] Re: saving related objects using has_many_through associations
Sergio Bayona wrote:> This only saves the @person but not the @address. Shouldn''t it save both? > > @person = Person.new(params[:person]) > @address = Address.new(params[:address]) > @person.address << @address > @person.save > > here is what I have: > > class Person < ActiveRecord::Base > has_many :addressables > has_many :addresses, :through => :addressables > end > > class Address < ActiveRecord::Base > has_many :addressables > has_many :people, :through => :addressables > end > > class Addressable < ActiveRecord::Base > belongs_to :address > belongs_to :person > endNo, at present you have to explicitly create the Addressable object. You may be better of using a has_and_belongs_to_many association, since your Person<->Address association has no accessory attributes. -- We develop, watch us RoR, in numbers too big to ignore.
Hi Folks, I just upgraded rails from 1.0.0 to 1.1.2. Suddenly, some of my "if conditions" stopped working as expected. It seems as though Rails/ActiveRecord now treats tinyint(1) columns as boolean instead of integers (like v1.0.0). I was just wondering if anybody else has experienced similar behavior? If so, is there a quick work-around that doesn''t involve me doing a search and replace and retesting my entire app? TIA!
BTW, I am using mysql 5.0.16 and ruby 1.8.2 On 4/10/06 4:29 PM, "Vince Puzzella" <vpuz@rogers.com> wrote:> Hi Folks, > > I just upgraded rails from 1.0.0 to 1.1.2. Suddenly, some of my "if > conditions" stopped working as expected. It seems as though > Rails/ActiveRecord now treats tinyint(1) columns as boolean instead of > integers (like v1.0.0). > > I was just wondering if anybody else has experienced similar behavior? If > so, is there a quick work-around that doesn''t involve me doing a search and > replace and retesting my entire app? > > TIA! > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
yeah ive been experiencing the same thing, anybody know how to get around this or what the deal is? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---