[英]Is Not Null Scope Causing Errors in PSQL Rails App
我有一个在heroku上运行的rails应用程序,由于某种原因,以下范围导致很多麻烦并在PSQL中引发错误('rating'是一个整数):
scope :rated, where("posts.rating <>''")
所以我很自然地尝试了下面列出的所 这些不会导致任何错误,但显示空评级值STILL的帖子。
scope :rated, where("posts.rating IS NOT ?", nil)
scope :rated, where("posts.rating > 0")
scope :rated, where("posts.rating IS NOT NULL")
提前致谢!
如何组合它们?
scope :rated, where("posts.rating IS NOT NULL AND posts.rating > 0")
您上面的第三个选项应该适用于标准PSQL,但您也可以尝试:
posts.rating <> NULL or
posts.rating NOTNULL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.