# Problem with ActiveRecord::AssociationTypeMismatch

**URL:** <https://www.ruby-forum.com/t/problem-with-activerecord-associationtypemismatch/142941>\
**Category:** Rails\
**Created:** [July 13, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-associationtypemismatch/142941 "2008-07-13T20:27:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 13, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-associationtypemismatch/142941/1 "2008-07-13T20:27:43Z")

</div>

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:in`replace’  
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:in`replace’  
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:in`initialize’  
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

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 13, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-associationtypemismatch/142941/2 "2008-07-13T21:06:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![christoph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@christoph](https://www.ruby-forum.com/u/christoph)\
**Post date:** [July 13, 2008, 9:15pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-associationtypemismatch/142941/3 "2008-07-13T21:15:10Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
