error: Association named ...... was not found
After totally reworking one of my apps (have to gut it since I'm changing it's focus), I botted up mongrel, expecting to see everything was hunky dory and working great. I browsed to one of my list actions and I got this error:
Hmmm. I know that's how you spell user so I knew that wasn't the problem. What the problem ended up being was I was trying to eagerly load this object's users with a :include => 'user'. This worked in the past because this object's table had a user_id column in it. But, due to me reworking it, it no longer did. So to sum how I resolved this errror, I just removed the
and it worked fine.
Association named 'user' was not found; perhaps you misspelled it?
Hmmm. I know that's how you spell user so I knew that wasn't the problem. What the problem ended up being was I was trying to eagerly load this object's users with a :include => 'user'. This worked in the past because this object's table had a user_id column in it. But, due to me reworking it, it no longer did. So to sum how I resolved this errror, I just removed the
, :include => 'user'
and it worked fine.
3 Comments:
At 3:10 PM, Anonymous said…
Hey, I'm wondering if you have some more insight on this problem, since I'm running into the same issue and I simply don't understand the logic behind this error. Does this mean we should be removing :include in all cases?
At 3:35 PM, Curtis said…
not in all cases. If you know which include is hurting you, take out each include parameter until it works. For me, I was trying to load something that did not have an association with the model I was trying to include it with.
At 5:48 PM, Mario Olivio Flores said…
Sometimes, you need to have an include statement, and leaving it off won't cut it. In my case, I was trying to include table B when doing a find on table A. I had my associations set up in my models (belongs_to and has_many). Then I realize that I forgot to add a B_id table to my A table. Last, I realized that my B table didn't actually have IDs.
Post a Comment
<< Home