Last active
February 9, 2017 23:23
-
-
Save alexdean/1edd9def0e83337fea93c97377a121b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TempModelBuilder | |
def self.build(sql, size) | |
final_table_name = "tmp_#{Digest::MD5.hexdigest(sql)}" | |
clazz = Class.new(ActiveRecord::Base) | |
clazz.table_name = final_table_name | |
# do stuff to create & populate the table | |
clazz | |
end | |
end | |
# you can create as many of these as you want. | |
model1 = TempModelBuilder.build('select * from ...', 50) | |
model2 = TempModelBuilder.build('select * from ...', 50) | |
# do activerecordish things now | |
result = model1.joins(:whatever).count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment