Skip to content

Instantly share code, notes, and snippets.

View kernel-io's full-sized avatar

kernel-io kernel-io

View GitHub Profile
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}'