Problem with ActiveRecord::AssociationTypeMismatch

Hi all !
I’ve written a Character model, each character has many Attributes. My
schema.rb looks like this:

create_table “characters”, :force => true do |t|
t.string “first_name”
t.string “last_name”
t.integer “user_id”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “attributes”, :force => true do |t|
t.string “name”
t.float “value”
t.integer “character_id”
t.datetime “created_at”
t.datetime “updated_at”
end

And the models look like this:
class Character < ActiveRecord::Base
has_many :attributes

end

class Attribute < ActiveRecord::Base
belongs_to :character
end

When I want to create a new instance by calling
c = Character.new :first_name => “hello”, :last_name => “world”
I get this Error:
ActiveRecord::AssociationTypeMismatch: Attribute(#17724630) expected,
got Array(#104100)
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
associations/association_proxy.rb:214:in raise_on_type_mismatch' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ associations/association_collection.rb:229:inreplace’
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
associations/association_collection.rb:229:in each' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ associations/association_collection.rb:229:inreplace’
from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
associations.rb:1149:in attributes=' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2130:ininitialize’
from (irb):1:in `new’
from (irb):1
from :0

I have no idea why I get this error, since I don’t specify the
“attributes” key. I hope you can help me, thank you very much in
advance.

Greetings,
Christoph

On 13 Jul 2008, at 19:27, Christoph wrote:

t.datetime “updated_at”
And the models look like this:
class Character < ActiveRecord::Base
has_many :attributes

Don’t do this. You’ll overwrite the existing attributes and
attributes= methods. Bad stuff will happen.

Fred

Oh my god, I didn’t know that “attributes” has a special meaning.
Thank you very much,

Christoph

On 13 Jul., 21:05, Frederick C. [email protected]