【发布时间】:2021-04-27 14:47:54
【问题描述】:
在 Rails 4.2.11 中,
User.find_by(name: 'name', email: 'email')
返回一个ActiveRecord::Relation(包含一个用户实例的数组)而不是一个用户实例。
#<ActiveRecord::Relation [#<User id: 1, name: "Tester Test", email: "stester@xxx.xxx", created_at: "2021-04-27 14:08:49", updated_at: "2021-04-27 14:08:49">]>
This is happening in the context of a failing cucumber test where I create an authorization record and a user record. The authorization record is found, but the user record comes back only as a Relation no matter what I do. Tried .first, .take, several other ways to retrieve the instance.
这与User.where 的输出相同,而不是User.find_by。知道为什么会这样吗???
【问题讨论】:
标签: ruby-on-rails-4 activerecord