gpt4 book ai didi

mysql - Rails where 子句 with between 在 mysql 中不起作用

转载 作者:行者123 更新时间:2023-11-29 05:24:21 25 4
gpt4 key购买 nike

我在 rails 中有以下查询...

@registrations = Registration.where(Orientation.where(class_date: @start_date..@end_date))

查询本身不会抛出错误,但是如果我尝试检查@registrations 对变量执行任何操作,我会收到错误...

Cannot visit ActiveRecord::Relation

有什么想法吗?

最佳答案

Orientation.where(class_date: @start_date..@end_date)

做你喜欢的范围查询

SELECT * FROM orientations WHERE class_date BETWEEN <start_date> AND <end_date>

更新

Registration.where(created_at: @start_date..@end_date).
joins(:orientation).
where('orientations.created_at' => @start_date..@end_date)

将生成以下 SQL我认为这是你需要的

SELECT registrations.* FROM registrations INNER JOIN orientations ON orientations.id = registrations.orientation_id WHERE (registrations.created_at BETWEEN '2014-02-17 16:01:41' AND '2014-02-19 16:01:41') AND (orientations.created_at BETWEEN '2014-02-17 16:01:41' AND '2014-02-19 16:01:41')

关于mysql - Rails where 子句 with between 在 mysql 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21891681/

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