gpt4 book ai didi

Ruby rails - 如何找到多个选项?

转载 作者:数据小太阳 更新时间:2023-10-29 06:53:51 24 4
gpt4 key购买 nike

我想根据多个参数查找记录。并且这些参数有多个选项。

As "SELECT something FROM mytable WHERE user_name="xyz" and status=("Active" OR "Deleted")

我如何将其转换为 Rails 语句?

Person.find_by_user_name_and_status(user_name, status) # this doesn't take the OR operator 

最佳答案

我现在无法测试,但你试过了吗?

Person.find_all_by_user_name_and_status(user_name, ["active", "deleted"])

如果以上方法不起作用,这应该...

Person.where(:user_name => "xyz", :status => ["active", "deleted"])
# translates to:
# "select * from persons where username = 'xyz' and status in ('active', 'deleted')"

您应该查看 Rails Guide for Active Record:http://guides.rubyonrails.org/active_record_querying.html

关于Ruby rails - 如何找到多个选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189556/

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