wbsurfver-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2011-Jul-14 21:38 UTC
puzzled by polymorphic related error
Here is what my schema and models look like currently and the error I get is below .. create_table "attributes", :force => true do |t| t.string "field_name" t.integer "reliability" t.integer "attribute_record_id" t.string "attribute_record_type" end create_table "parsed_sections", :force => true do |t| t.integer "section_id" t.integer "conversion_id" t.string "sect_typ" t.text "txt" t.boolean "overrun" t.text "end_marker" t.datetime "created_at" t.datetime "updated_at" end class Attribute < ActiveRecord::Base belongs_to :attribute_record, :polymorphic => true end class ParsedSection < ActiveRecord::Base belongs_to :conversion has_many :attributes, :as => :attribute_record end rails console irb(main):005:0* psect = ParsedSection.new => #<ParsedSection id: nil, section_id: nil, conversion_id: nil, sect_typ: nil, txt: nil, overrun: nil, end_marker: nil, created_at: nil, updated_at: nil> irb(main):006:0> psect.save ActiveRecord::AssociationTypeMismatch: Attribute(#24728580) expected, got String (#2258112) from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/associations/association_proxy.rb:260:in `raise_on_type_mismatch'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/associations/association_collection.rb:520:in `block in remove_records'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/associations/association_collection.rb:520:in `each'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/associations/association_collection.rb:520:in `remove_records'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/associations/association_collection.rb:221:in `delete'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/transactions.rb:331:in `restore_transaction_record_state'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/transactions.rb:250:in `rescue in rollback_active_record_state!'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/transactions.rb:254:in `rollback_active_record_state!'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/ lib/active_r ecord/transactions.rb:236:in `save'' from (irb):6 from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/ rails/comman ds/console.rb:44:in `start'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/ rails/comman ds/console.rb:8:in `start'' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/ rails/comman ds.rb:23:in `<top (required)>'' from script/rails:6:in `require'' from script/rails:6:in `<main>'' irb(main):007:0> -- 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.
wbsurfver@... <wbsurfver@...> writes:> >....> > class Attribute < ActiveRecord::Base > belongs_to :attribute_record, :polymorphic => true > end > > class ParsedSection < ActiveRecord::Base > belongs_to :conversion > has_many :attributes, :as => :attribute_record > end >I believe you will have problems with columns called "attributes", especially with has_many associations. -- 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.