2
我很難讀取命名作用域的API。每個「出價」都有一個user_id和一個auction_id。我需要一個範圍來返回用戶已經出價的拍賣。命名作用域的API
拍賣
class Auction < ActiveRecord::Base
has_many :bids
named_scope :current, lambda {
{:conditions => ["scheduled_start < ?", 0.minutes.ago],
:order => 'scheduled_start asc'}
}
named_scope :scheduled, lambda {
{:conditions => ["scheduled_start > ?", 0.minutes.ago],
:order => 'scheduled_start asc'}
}
end
投標
class Bid < ActiveRecord::Base
belongs_to :user
belongs_to :auction
validates_numericality_of :point, :on => :create
#
# how do I write a named scope to check if a user has bid on an auction?
end