# Plugin belongs\_to Model Association Bug

**URL:** <https://www.ruby-forum.com/t/plugin-belongs-to-model-association-bug/127556>\
**Category:** Rails\
**Created:** [January 30, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/plugin-belongs-to-model-association-bug/127556 "2008-01-30T12:05:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 30, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/plugin-belongs-to-model-association-bug/127556/1 "2008-01-30T12:05:41Z")

</div>

Hey all,

I’m not positive if this is a Engines bug, but it seems very peculiar  
and a few hours of Googling haven’t given me any good leads yet, so I  
thought I’d see if it makes sense to any of you:

I am writing a new version of the savage\_beast plugin (implements  
Beast forums as a plugin) that’s Rails 2.0 compatible, and I am having  
trouble with the many models in the plugin that refer to the User  
model (which lives in my project). For example, my Post class (part  
of the savage\_beast plugin) has

class Post \< ActiveRecord::Base  
belongs\_to :forum  
belongs\_to :user  
belongs\_to :topic

…  
end

I can set the forum, user, and topic for this class fine, and they  
save without issue. However, when I go to access the user association  
later on, I can only get its database fields, not any of the methods  
that are defined in the User model. That is,

@post.user[:some\_database\_attribute] will display fine  
@post.user.any\_method\_at\_all will give me a “No method found” error.

If I check what kind of class @post.user is, Ruby will report it is a  
“User” class. I have tried to hack around this by doing a “def user  
{ User.find(user\_id) }” in the plugin, but users are used as  
associations in numerous instances in numerous models, sometimes as  
has\_many\_throughs, so besides being ugly, I don’t think this hack is  
going to be viable across the board (though doing a User.find of the  
user\_id does return a model with methods intact).

Do any of you have any suggestions about how I could fix (or start to  
debug) this issue?

Thanks,  
Bill Harding
