AssociationTypeMissmatch


#1

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


#2

Usually end up replying to my own threads :slight_smile:

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