# AssociationTypeMissmatch

**URL:** <https://www.ruby-forum.com/t/associationtypemissmatch/87166>\
**Category:** Rails\
**Created:** [February 28, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/associationtypemissmatch/87166 "2007-02-28T17:42:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/cab0a1/32.png) [@Fredrik](https://www.ruby-forum.com/u/Fredrik)\
**Post date:** [February 28, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/associationtypemissmatch/87166/1 "2007-02-28T17:42:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fredrik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/cab0a1/32.png) [@Fredrik](https://www.ruby-forum.com/u/Fredrik)\
**Post date:** [February 28, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/associationtypemissmatch/87166/2 "2007-02-28T18:33:31Z")

</div>

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
