gpt4 book ai didi

ruby-on-rails - Rails 3 参数错误 : Unknown key: begin_date

转载 作者:数据小太阳 更新时间:2023-10-29 07:48:41 26 4
gpt4 key购买 nike

我有一个 Waiver 对象,它有_many 个成员资格。我想弄清楚豁免是否具有给定季度的成员资格:

def has_current_membership?
memberships.count("begin_date >= :begin_date AND end_date <= :end_date", { :begin_date => Time.now.beginning_of_quarter, :end_date => Time.now.end_of_quarter }).count > 0
end

然而,这给了我 ArgumentError: Unknown key: begin_date。但是,成员资格确实有一个 begin_date 列,因为如果我在控制台中执行 Waiver.first.memberships,我会得到:

[#<Membership id: 20, waiver_id: 1, begin_date: "2011-10-01", end_date: "2012-01-01", created_at: "2011-11-19 07:10:10", updated_at: "2011-11-19 07:10:10">] 

我做错了什么?

最佳答案

您应该使用 .where 作为查找条件,而不是 .count 两次:

memberships.where("begin_date >= :begin_date AND end_date <= :end_date", { :begin_date => Time.now.beginning_of_quarter, :end_date => Time.now.end_of_quarter }).count > 0

关于ruby-on-rails - Rails 3 参数错误 : Unknown key: begin_date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8196332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com