Hi - I have a model with a user-specific has_one relationship,
meaning, my model, Story, has one Vote, but only on a per-user basis.
So, I addressed this issue by adding a has_one relationship:
has_one :current_user_vote, :class_name => 'Vote', :conditions =>
"user_id = #{Story.current_user ? Story.current_user.id : -1}"
And, I added a cattr_accessor, current_user (so now the model Story
has a current user).
And, when the user logs in (or gets logged in by cookie), the method
set_current_user gets called automatically, which looks like this:
def self.set_current_user user
if user
holder = user.id
else
holder = -1
end
reflect_on_association(:current_user_vote).options[:conditions] =
"votes.user_id = #{holder}"
self.current_user = user
end
This works fine, unless I enable config.cache_classes, then, the first
user who accesses the site after the server is restarted gets his id
set to current_user, and everyone else afterward gets the first guy's
user_id set in the association.
So, is there a way to disable only model caching, and cache everything
else? Or, is this a bug?
Thanks for any help,
Dino
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---