Rails 4.1 ActiveRecord::relation is no more like A

2019-01-25 03:20发布

in Rails 4.0.4 this code work:

mailboxes = Mailbox.order(:mailbox)
mailboxes.keep_if do |mailbox|
  # test
end

in Rails 4.1.0 it break with NoMethodError (undefined method keep_if for <Mailbox::ActiveRecord_Relation:0x5494f80>)

and has to be changed to

mailboxes = Mailbox.order(:mailbox).to_a
mailboxes.keep_if do |mailbox|
  # test
end

I don't find any information about that

Any idea?

1条回答
爷的心禁止访问
2楼-- · 2019-01-25 04:08

Its in release notes for rails 4.1

Relation no longer has mutator methods like #map! and #delete_if. Convert to an Array by calling #to_a before using these methods. (Pull Request)

Since keep_if is a mutator method, its removed from Relation

查看更多
登录 后发表回答