I have a 3 simple models:
class User < ActiveRecord::Base
has_many :subscriptions
end
class Game < ActiveRecord::Base
has_many :subscriptions
end
class Subscription < ActiveRecord::Base
belongs_to :user
belongs_to :game
end
What I am wondering is, is it possible when I query for Games to include another attribute called ‘is_subbed’ which will contain wether a particular user is subscribed to a game? Something like:
a_user = User.first
games = Game.scoped
games.conditions blah blah blah
and games will include a ‘virtual’ or in memory attribute that will be custom to a_user called is_subed
You can make a class method and an instance method (for a single game) like so:
To get this result for each game using the query API, you can do this:
This will give you an
is_subscribedparameter on each game object returned.