Forum: Ruby on Rails AssociationTypeMissmatch

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fredrik (Guest)
on 2007-02-28 18:42
(Received via mailing list)
Hi,

I've seen a few threads here about HABTM raising
AssociationTypeMissmatch exceptions, but no definate answer.
I'm having this problem with one of my relationships and cannot figure
out what is causing it. The other threads implies that it is something
in my code, and I must say I agree that it is likely, but I have 200+
controllers and <300 models, so this is quite an interesting task even
though the majority can be ruled out.

My error:
Customer expected, got Customer

Caused by:
@user = User.find(params[:id])
customer = Customer.find(params[:customer_id])

@user.customers.delete(customer) #This statement
and
@user.customers << customer #This statement.


Actually, the second one worked once in the middle of my testing which
makes it even worse, but just once.

Thanks,

Fredrik
Fredrik (Guest)
on 2007-02-28 19:33
(Received via mailing list)
Usually end up replying to my own threads :)

Should probably mention that I started with active_rbac (modified by
now).

I found a workaround though:

customer.users.delete(user)
customer.users << user
=Reverse it. Something apparently is up with the user model. I have an
instance of the user model in the session (not with the customers
loaded), but I do a User.find on this one, since it is part of an
admin piece.

Fredrik
This topic is locked and can not be replied to.