# ActiveRecord::AssociationTypeMismatch

**URL:** <https://www.ruby-forum.com/t/activerecord-associationtypemismatch/241197>\
**Category:** Rails\
**Created:** [May 18, 2014, 6:46am UTC](https://www.ruby-forum.com/t/activerecord-associationtypemismatch/241197 "2014-05-18T06:46:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [May 18, 2014, 6:46am UTC](https://www.ruby-forum.com/t/activerecord-associationtypemismatch/241197/1 "2014-05-18T06:46:11Z")

</div>

Sorry for my english.

I have to create twitter like app. I created 3 models User, Tweet,  
Followership

class User \< ActiveRecord::Base  
has\_many :tweets  
accepts\_nested\_attributes\_for :tweets  
has\_many :followerships, class\_name: ‘Followership’, foreign\_key:  
‘followed\_id’  
has\_many :followerships, class\_name: ‘Followership’, foreign\_key:  
‘follower\_id’  
has\_many :followed, through: :followedships, source: :followed  
has\_many :followers, through: :followerships, source: :follower  
end  
class Tweet \< ActiveRecord::Base  
belongs\_to :user  
end  
class Followership \< ActiveRecord::Base  
belongs\_to :follower, class\_name: ‘User’  
belongs\_to :followed, class\_name: ‘User’  
end

I have _yaml_ file with _UTF-8_ data to add to my db. I changed my  
_seeds.rb_ file in such a way:  
seed\_file = File.join(Rails.root, ‘db’, ‘seeds.yml’)  
config = YAML::load\_file(seed\_file)  
User.create(config[“users”])  
Followership.create(config[“followerships”])

Then i tried to run _rake db:seed_ and got  
alexkd@Active-pc:~/WebDev/rails/twitter$ rake db:seed  
rake aborted!  
ActiveRecord::AssociationTypeMismatch: Tweet(#97039630) expected, got  
Hash(#81744670)  
…

Whats the problem? I have no ideas. _ruby 2.0, Rails 4.1.0, sQlite3_

---

<div class="post-metadata">

**Author:** ![McCauley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@McCauley](https://www.ruby-forum.com/u/McCauley)\
**Post date:** [May 18, 2014, 10:25pm UTC](https://www.ruby-forum.com/t/activerecord-associationtypemismatch/241197/2 "2014-05-18T22:25:47Z")

</div>

On Saturday, 17 May 2014 20:35:47 UTC-4, McCauley wrote:

> ‘followed\_id’  
> belongs\_to :followed, class\_name: ‘User’  
> alexkd@Active-pc:~/WebDev/rails/twitter$ rake db:seed  
> rake aborted!  
> ActiveRecord::AssociationTypeMismatch: Tweet(#97039630) expected, got  
> Hash(#81744670)  
> …

Hard to say for certain without a backtrace or the yaml, but my first  
guess  
would be that you’re trying to assign to `tweets` instead of the  
`tweets_attributes` method that `accepts_nested_attributes` has  
generated.

–Matt J.
