我的活动记录搜索有问题。我以为我的模型设置正确,但我的加入很差(不确定加入或联合是否是正确的方法?应该不难)。
我有指南为具有 start_dates 的旅行创建出价。我想创建一个已过期的出价列表(即开始日期是过去的)。如果出价被拒绝,指南也可以有 LosingBids
在一个完美的世界中,我会有一个结果集,其中包括该指南的失败出价和过期出价,但我发现有 2 个不同的结果集。不幸的是,我无法让任何“过期的投标”发挥作用。代码注释中的结果/错误。
class GuidesController < ApplicationController
def expired_declined
#this declined_bids call works
@declined_bids = LosingBid.where("guide_id = ?", current_guide.id.to_s)
#this expired_bids call returns Trips, not Bids
@expired_bids = Bid.where("guide_id = ?", current_guide.id.to_s).expired
#this expired_bids call gives me the following error:
#SQLite3::SQLException: no such column: trips.start_date: SELECT 1 AS one FROM #”bids" WHERE (guide_id = '1') AND (trips.start_date < '2018-05-30') LIMIT ?
@expired_bids = Bid.where("guide_id = ?", current_guide.id.to_s).where("trips.start_date < ?", Date.today)
end
end
class Guide < ApplicationRecord
has_many :bids
has_many :losing_bids
end
class Trip < ApplicationRecord
has_many :bids
end
class Bid < ApplicationRecord
belongs_to :trip
belongs_to :guide
def self.expired
Trip.where("start_date <= ?", Date.today) #.where("guide_id = ?", current_guide.id.to_s)
end
end
class LosingBid < ApplicationRecord
belongs_to :trip
belongs_to :guide
end