Last active
April 14, 2019 09:17
-
-
Save localhostdotdev/22e721f7597d0956b7da313daad08616 to your computer and use it in GitHub Desktop.
ApplicationRecord.sql('select * from users left join accounts on accounts.user_id = users.id and accounts.kind = ?', 'something')
This file contains hidden or 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 ApplicationRecord < ActiveRecord::Base | |
| def self.sql(sql, *values) | |
| ActiveRecord::Base.connection.execute( | |
| ActiveRecord::Base.send(:sanitize_sql_array, [sql, *values]) | |
| ).each.to_a | |
| end | |
| end | |
| users = ApplicationRecord.sql('select * from users') | |
| users_and_accounts = ApplicationRecord.sql('select * from users left join accounts on accounts.user_id = users.id and accounts.kind = ?', 'something') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment