Is there an ActiveRecord version of Hash.Merge?
I have a very large set of data on which I'm doing a great deal of post-query manipulation (sorting, filtering, etc etc). I would like do all this manipulation on an array of ActiveRecord objects that contains only the information necessary to the sorting, filtering, and paging, and then add the data necessary for display at the end.
For example, let's say I have a database with two tables: baseball_players and player_infos. The baseball_players table contains all of the interesting stuff (stats, team, name, birthday开发者_高级运维, etc etc etc). Player_infos contains player_id, player_rank, and player_position. I have 15000 players, and I want to find the numbers 100-150 of the best catchers of all times. I retrieve an array of all player_infos, filter to only catchers, sort by player_rank, and then retrieve records 100-150.
What is the best way to merge the resulting player_info records with their corresponding baseball_player records? Hash.merge would work perfectly, but I don't want to convert these objects to Hashes. Does ActiveRecord support something similar?
Note that I have a restriction where I cannot simply query the data using SQL - I have to manually sort and filter an object containing all 15000 player_info records.
I believe you are looking for ActiveRecord::Base#update
.
精彩评论