gpt4 book ai didi

ruby-on-rails - 你能通过三个属性找到吗?

转载 作者:太空宇宙 更新时间:2023-11-03 18:29:47 26 4
gpt4 key购买 nike

在 Rails 中是否允许这种类型的东西:Model.find_by_X_and_Y_and_Z(attribute1, attribute2, attribute3)

最佳答案

来自 http://ar.rubyonrails.org/classes/ActiveRecord/Base.html

It‘s also possible to use multiple attributes in the same find by separating them with "and", so you get finders like Person.find_by_user_name_and_password or even Payment.find_by_purchaser_and_state_and_country. So instead of writing Person.find(:first, :conditions => ["user_name = ? AND password = ?", user_name, password]), you just do Person.find_by_user_name_and_password(user_name, password).

关于ruby-on-rails - 你能通过三个属性找到吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5985599/

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