william.harding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-30 11:05 UTC
Plugin belongs_to Model Association Bug
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Apparently Analagous Threads
- 2 belongs_to to the same parent table
- has_many & belongs_to with Plugins (login_engine)
- undefined method `has_many' for Object:Class +Savage Beast 2.3 plugin
- Polymorphic and standard association issue
- ActiveRecord-2.2.2, association preloading, joins and order parameter weirdness
