Butu
2011-Feb-24 05:56 UTC
Rails 3 save parent model and association if nested attributes validation fails for uniqueness
Hi, Song has_and_belongs_to_many :people accepts_nested_attributes_for :people Person validates :uniqueness => true If person record not present, nested attributes working great! in rails way. i.e., inserting into songs, people and people_songs table correctly. I am interested in:- *If there is person exist, it should skip insertion into people table but data should be inserted in songs and people_songs table (association table). * * * There are lots of approach to solve this problem. I usually comes with some ugly way to deal with this. Can some body suggest me the proper Rails way to handle this. Thanks! Butu -- 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.
Dan
2011-Apr-09 02:13 UTC
Re: Rails 3 save parent model and association if nested attributes validation fails for uniqueness
Hi, I am also facing the same problem. Unfortunately googling around, I see recommendations of using the method find_or_create_by. But what if I''m using nested attributes to save? Any advise? On Feb 24, 1:56 pm, Butu <but...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Song > has_and_belongs_to_many :people > accepts_nested_attributes_for :people > > Person > validates :uniqueness => true > > If person record not present, nested attributes working great! in rails way. > i.e., inserting into songs, people and people_songs table correctly. > > I am interested in:- > *If there is person exist, it should skip insertion into people table but > data should be inserted in songs and people_songs table (association > table). * > * > * > There are lots of approach to solve this problem. I usually comes with some > ugly way to deal with this. Can some body suggest me the proper Rails way to > handle this. > > Thanks! > Butu-- 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.