fixed has many through join

Fixed has many through join when the relation is a belong_to b belong_to c,
current code expect a has_many b belong_to c.
The test code throws an sql error without the fix.