hi, im trying to update a relation through has many, but i cannot figure out how to do it, so i thought i can just delete all the relation and create them again, but i get error on clear method?>> c = Campaign.last=> #<Campaign id: 5, name: "sortable", description: "pokads", default_segment: nil, account_id: 4, promotion_created: true>>> c.campaigns_segments=> [#<CampaignsSegments segment_id: 1, campaign_id: 5, sortable: nil>, #<CampaignsSegments segment_id: 5, campaign_id: 5, sortable: nil>]>> c.campaigns_segments.clearNoMethodError: undefined method `in'' for nil:NilClass from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/has_many_association.rb:79:in `delete_records'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:222:in `delete'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:527:in `remove_records'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:158:in `transaction'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/transactions.rb:204:in `transaction'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:157:in `transaction'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:524:in `remove_records'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:221:in `delete'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:167:in `delete_all'' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/associations/association_collection.rb:248:in `clear'' from (irb):50 Is this rails 3 error or what? please help :) thanks.. -- 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-/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.
Hope you figured this out six months ago, but I just spent a few minutes on this issue and found the answer after finding this unanswered post. It may not be your solution, but it solved my issue with this exact error. For simple mapping tables using the :has_many relationship, the mapping table needs to have an autoincrementing primary key, ''id''. If you create the table with :id => false, then you''re going to have this problem once you try to start deleting from this table (you can insert and read from it fine). This is unlike relationships with the :has_and_belong_to_many, which mapping tables do not require (and in fact can not have, I don''t think) a PK ''id'' field. Jamal Soueidan wrote in post #957804:> hi, > > im trying to update a relation through has many, but i cannot figure out > how to do it, so i thought i can just delete all the relation and create > them again, but i get error on clear method? > >>> c = Campaign.last > => #<Campaign id: 5, name: "sortable", description: "pokads", > default_segment: nil, account_id: 4, promotion_created: true> >>> c.campaigns_segments > => [#<CampaignsSegments segment_id: 1, campaign_id: 5, sortable: nil>, > #<CampaignsSegments segment_id: 5, campaign_id: 5, sortable: nil>] >>> c.campaigns_segments.clear > NoMethodError: undefined method `in'' for nil:NilClass > from> Is this rails 3 error or what? > > please help :) > > thanks..-- 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-/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.