Rails 中基于日期的关系问题
我在 Rails 内建立了一个基于日期条件的一对一关系,这意味着只应返回今天的订单。
has_one :todays_order, :through => :patient_orders, :source => :daily_order ,:conditions => ["order_for_date = ?", Date.current]
假设昨天有今天的订单,但今天应该没有今天的订单,因为不存在日期等于今天的订单。
仅当我调用控制器并获得包含该数据的 json 响应时,才会发生这种情况。 如果我尝试在控制台中重现它,它的行为是正确的,并给我 nil
作为今天订单的值。 我的环境是开发。
另一个奇怪的事情是,服务器重新启动后,今天的订单将正确返回,因此似乎存在诸如缓存活动之类的东西。可能是这样吗?
I build a one-to-one relationship within rails with a date based condition, which means only the order of today should be returned.
has_one :todays_order, :through => :patient_orders, :source => :daily_order ,:conditions => ["order_for_date = ?", Date.current]
Lets say for yesterday there is a todays order but today there should be no todays order because there doesn't exist a order with a date equal to the date of today.
This only happens when I call a controller and get a json response with that data included.
If i try to reproduce that within the console it behaves right and gives me nil
as value of todays order.
My environment is development.
Another curious thing is, that after a server restart the todays order will returned right, so it seems that there is something like caching active. Could that be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的方法是加载关联查询并传递一个真实值:
或者您可以尝试将查询包装在这种块中:
或强制清除缓存:
The best way is to load your association query passing it a true value:
Or you can try wrapping the query in this kind of block:
or forcing the cache to clear: