morgler
2009-Feb-02 13:37 UTC
ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-02 14:15 UTC
Re: ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))
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 http://www.spacevatican.org/2008/9/28/required-or-not ) Fred> > > 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 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
morgler
2009-Feb-02 15:04 UTC
Re: ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))
thanks for the link! it solved my problem :)! thank you so much! matthias On 2 Feb., 15:15, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 (seehttp://www.spacevatican.org/2008/9/28/required-or-not > ) > > Fred > > > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---