ruby-on-rails Rails抛出Relation#all is deprecated错误

ubof19bj  于 2023-07-01  发布在  Ruby
关注(0)|答案(1)|浏览(109)
Universe::Animals.wild.types.find { |x| x[:legs] == 4 }

Rails在扔

Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published:true).to_a`)'

如何重构此语句以删除弃用警告。不希望抑制弃用

d7v8vwbk

d7v8vwbk1#

1.它告诉你!you can call #to_a (e.g. Post.where(published:true).to_a)
1.别这样!

Universe::Animals.wild.types.find_by(legs: 4)

将获取一个具有4条腿的Animals示例-假设腿是一个列而不是一些自定义方法。

相关问题