First, what you really want is to identify the area for your options.
class UserOfferChoice < ActiveRecord::Base
belongs_to :user
belongs_to :offer
scope :seen, where(seen: true)
scope :accepted, where(accepted: true)
end
What allows you to do this
Offer.find(11).user_offer_choices.seen
and get the criteria:
Offer.find(1).user_offer_choices.seen.map{|choice| choice.user}.map{|user| user.criterion}
.
class Offer < ActiveRecord::Base
has_many :user_offer_choices
has_many :users, :through => :user_offer_choices
end
, .
Offer.find(1).users
Rails 3, Rails 2.3.5 named_scopes. _scopes , . Rails 3 , , , . , , , !
class User < ActiveRecord::Base
has_one :criterion
has_many :user_offer_choices
has_many :offers, :through => :user_offer_choices
scope :seen, UserOfferChoice.seen
scope :accepted, UserOfferChoice.accepted
end
:
Offer.find(1).users.seen
:
Offer.find(1).users.seen.map{|user| user.criterion}
, . , , . , , Rails :
config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural /^criterion$/i, 'criteria'
end