# ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))

**URL:** <https://www.ruby-forum.com/t/activerecord-associationtypemismatch-user-54754560-expected-got-user-54510280/159221>\
**Category:** Rails\
**Created:** [February 2, 2009, 2:38pm UTC](https://www.ruby-forum.com/t/activerecord-associationtypemismatch-user-54754560-expected-got-user-54510280/159221 "2009-02-02T14:38:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morgler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@morgler](https://www.ruby-forum.com/u/morgler)\
**Post date:** [February 2, 2009, 2:38pm UTC](https://www.ruby-forum.com/t/activerecord-associationtypemismatch-user-54754560-expected-got-user-54510280/159221/1 "2009-02-02T14:38:13Z")

</div>

i keep getting this AssociationTypeMismatch error. i think this could  
be a bug related to ruby/rails when using mixins. heres a short  
version of my code:

# user.rb

require ‘friend\_invitation’  
require ‘friendship’

class User \< ActiveRecord::Base  
include FriendInvitationUser, FriendshipUser

…  
end

# friendship.rb

…

module FriendshipUser  
def self.included(includer)  
includer.class\_eval do  
has\_many :friends, :through =\> :friendship  
end  
end

# true, if other\_user is a friend of mine

def friend\_of?(other\_user)  
Friendship.between?(self, other\_user)  
end

…  
end

so basically I’m using modules to mixin new aspects into the User  
model (kinda like AOP in ruby). i believe that these mixins together  
with the require statements at the top of the User model file cause  
the AssociationTypeMismatch. if i get the error, a restart of my  
development server solves the problem - but that can’t be the  
solution. any ideas where this error comes from or what to do about  
it?

any help very appreciated!

matthias

---

<div class="post-metadata">

**Author:** ![morgler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@morgler](https://www.ruby-forum.com/u/morgler)\
**Post date:** [February 2, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/activerecord-associationtypemismatch-user-54754560-expected-got-user-54510280/159221/2 "2009-02-02T15:16:29Z")

</div>

On 2 Feb 2009, at 13:37, morgler wrote:

> i keep getting this AssociationTypeMismatch error. i think this could  
> be a bug related to ruby/rails when using mixins. heres a short  
> version of my code:
> 
> # user.rb
> 
> require ‘friend\_invitation’  
> require ‘friendship’  
> using require like this can bust stuff (see  
> [Required or Not ? - Space Vatican](http://www.spacevatican.org/2008/9/28/required-or-not)  
> )

Fred

---

<div class="post-metadata">

**Author:** ![morgler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@morgler](https://www.ruby-forum.com/u/morgler)\
**Post date:** [February 2, 2009, 4:05pm UTC](https://www.ruby-forum.com/t/activerecord-associationtypemismatch-user-54754560-expected-got-user-54510280/159221/3 "2009-02-02T16:05:22Z")

</div>

thanks for the link! it solved my problem :)! thank you so much!

matthias
