lib/rls_rails/dsl/policy.rb
def using_relation *rels
      # Unwrap arguments given in a style like 'using_relation opener: :club_record_id, tenant: :tenant_id'
      rels = rels[0] if rels.size == 1 && rels[0].is_a?(Hash)

      @using = rels.map do |v|
        if v.is_a?(Array)
          fk = derive_fk @tbl, v[0]
          rel = v[1]
        else
          rel = v
          fk = derive_fk @tbl, v
        end

        rel_tbl = derive_rel_tbl(rel)
        <<-SQL
        EXISTS (
          SELECT NULL
          FROM #{rel_tbl}
          WHERE #{rel_tbl}.id = #{@tbl}.#{fk}
        )
        SQL
      end.join("      AND\n")
    end
# Shorthand for creating a policy which simply checks whether the given relations are all accessible
Shorthand for creating a policy which simply checks whether the given relations are all accessible
Shorthand for creating a policy which simply checks whether the given relations are all accessible
def using_relation *rels
      rels = rels[0] if rels.size == 1 && rels[0].is_a?(Hash)
      @using = rels.map do |v|
        if v.is_a?(Array)
          fk = derive_fk @tbl, v[0]
          rel = v[1]
        else
          rel = v
          fk = derive_fk @tbl, v
        end
        rel_tbl = derive_rel_tbl(rel)
        <<-SQL
        EXISTS (
          SELECT NULL
          FROM #{rel_tbl}
          WHERE #{rel_tbl}.id = #{@tbl}.#{fk}
        )
        SQL
      end.join("      AND\n")
    end
def using_relation * rels rels = rels [ 0 ] if rels . size == 1 && rels [ 0 ] . is_a? ( Hash ) @using = rels . map do | v | if v . is_a? ( Array ) fk = derive_fk @tbl , v [ 0 ] rel = v [ 1 ] else rel = v fk = derive_fk @tbl , v end rel_tbl = derive_rel_tbl ( rel ) <<-SQL 
        EXISTS (
          SELECT NULL
          FROM  #{ rel_tbl } 
          WHERE  #{ rel_tbl } .id =  #{ @tbl } . #{ fk } 
        )
         SQL end . join ( "      AND\n" ) end
Shorthand for creating a policy which simply checks whether the given relations are all accessible
Shorthand for creating a policy which simply checks whether the given relations are all accessible
# Unwrap arguments given in a style like 'using_relation opener: :club_record_id, tenant: :tenant_id'
rels