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
def for_user_with_role_sql(id, name) | |
sql = <<-SQL | |
WITH RECURSIVE organization_tree AS | |
( SELECT o.* | |
FROM organizations AS o | |
JOIN roles AS r | |
ON r.manageable_id = o.id | |
AND r.user_id = #{id} | |
AND r.manageable_type = 'Organization' | |
AND r.name = '#{name}' |