Last active
August 29, 2015 14:14
-
-
Save sclinede/74fb36cbc15b483b286e 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
company_id = 13011776 | |
real_regions = Company.find(company_id).region_ids_for_binding.join(',') | |
ActiveRecord::Base.connection.execute <<-SQL | |
UPDATE product_regions prs SET is_deleted = true, is_public = false | |
FROM ( | |
SELECT pr.id FROM products p JOIN product_regions pr ON p.id = pr.product_id | |
AND p.company_id = #{company_id} | |
AND pr.is_deleted IS false | |
WHERE pr.region_id NOT IN (#{real_regions})) t WHERE t.id = prs.id; | |
SQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment