Created
December 22, 2014 10:40
-
-
Save IlyaDonskikh/d01b047eecdf38ac95c1 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
sql = 'SELECT ctr.id, ctr.code as country_code, ctr.name as country_name, c.id, c.country_id, | |
c.code as city_code, c.name as city_name, a.code as airport_code, a.name as airport_name, a.city_id | |
FROM countries AS ctr INNER JOIN cities AS c INNER JOIN airports AS a | |
ON (ctr.name = ? OR ctr.code = ? OR c.name = ? OR c.code = ? OR a.code = ? OR a.name = ?) | |
AND ctr.id = c.country_id AND a.city_id = c.id' | |
sql = ActiveRecord::Base.send(:sanitize_sql_array, [sql, name.upcase, name, name.upcase, name, name.upcase, name]) | |
result_hash = ActiveRecord::Base.connection.execute(sql) | |
## Result (development) | |
SELECT ctr.id, ctr.code as country_code, ctr.name as country_name, c.id, c.country_id, | |
c.code as city_code, c.name as city_name, a.code as airport_code, a.name as airport_name, a.city_id | |
FROM countries AS ctr INNER JOIN cities AS c INNER JOIN airports AS a | |
ON (ctr.name = 'Москва' OR ctr.code = 'Москва' OR c.name = 'Москва' OR c.code = 'Москва' OR a.code = 'Москва' | |
OR a.name = 'Москва') AND ctr.id = c.country_id AND a.city_id = c.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment