Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.1 ActiveRecord::relation is no more like Array

Tags:

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?

like image 690
user1834205 Avatar asked Apr 09 '14 20:04

user1834205


1 Answers

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

like image 142
usha Avatar answered Oct 19 '22 00:10

usha