Skip to content

Instantly share code, notes, and snippets.

@listrophy
Created June 1, 2010 21:21
Show Gist options
  • Save listrophy/421518 to your computer and use it in GitHub Desktop.
Save listrophy/421518 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'active_record'
`rm ar_file.sqlite3`
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'ar_file.sqlite3'
ActiveRecord::Base.connection.create_table(:books) {|t| t.string :name }
ActiveRecord::Base.connection.create_table(:chapters) {|t| t.integer :book_id }
class Book < ActiveRecord::Base
has_many :chapters
accepts_nested_attributes_for :chapters
end
class Chapter < ActiveRecord::Base
belongs_to :book
end
book = Book.new
book.chapters << Chapter.new
book.chapters << Chapter.new
book_copy = Book.new.from_xml(book.to_xml(:include => :chapters)) # the failing line
source :rubygems
gem 'activerecord', '2.3.5'
gem 'sqlite3-ruby'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:262:in `raise_on_type_mismatch': Chapter(#2217156620) expected, got Hash(#2148223160) (ActiveRecord::AssociationTypeMismatch)
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:320:in `replace'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:320:in `each'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:320:in `replace'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1325:in `chapters='
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2746:in `send'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2746:in `attributes='
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2742:in `each'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2742:in `attributes='
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/serializers/xml_serializer.rb:160:in `from_xml'
from ./from_xml_fail.rb:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment