I have an array of objects, let\'s call it an Indicator. I want to run Indicator class methods (those of the def self.subjects variety, scopes, etc
ActiveRecord::Relation binds database query which retrieves data from database.
Suppose to make sense, We have array with objects of same class, then with which query we suppose to bind them?
When I run,
users = User.where(id: [1,3,4,5])
User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IN (1, 3, 4, 5) ORDER BY created_at desc
Here in above, usersreturn Relation object but binds database query behind it and you can view it,
users.to_sql
=> "SELECT `users`.* FROM `users` WHERE `users`.`id` IN (1, 3, 4, 5) ORDER BY created_at desc"
So it is not possible to return ActiveRecord::Relation from array of objects which is independent of sql query.