The following works, properly, but seems like I m probably not utilizing something in rails that I should be. The working bit is:
MaxOffer.joins("JOIN items ON items.id = max_offers.item_id")
.order( amount_in_cents desc )
.where( items.id = 20 )
.limit(5).collect do |moffer|
首先,我假定我没有必要明确使用加入书,因为模型是:
class MaxOffer < ActiveRecord::Base
belongs_to :item
belongs_to :user
class User < ActiveRecord::Base
has_many :bids
has_many :max_offers
But got errors when I tried to simply use item.id
in the where clause. Is there a more proper way to do this, or is explicitly including the join necessary?