Class: CanCan::ModelAdapters::Strategies::JoinedAliasExistsSubquery

Inherits:
Base
  • Object
show all
Defined in:
lib/cancan/model_adapters/strategies/joined_alias_exists_subquery.rb

Instance Attribute Summary

Attributes inherited from Base

#adapter, #relation, #where_conditions

Instance Method Summary collapse

Methods inherited from Base

#aliased_table_name, #initialize, #quoted_aliased_table_name, #quoted_table_name

Constructor Details

This class inherits a constructor from CanCan::ModelAdapters::Strategies::Base

Instance Method Details

#execute!Object


7
8
9
10
11
12
13
14
# File 'lib/cancan/model_adapters/strategies/joined_alias_exists_subquery.rb', line 7

def execute!
  model_class
    .joins(
      "JOIN #{quoted_table_name} AS #{quoted_aliased_table_name} ON " \
      "#{quoted_aliased_table_name}.#{quoted_primary_key} = #{quoted_table_name}.#{quoted_primary_key}"
    )
    .where("EXISTS (#{joined_alias_exists_subquery_inner_query.to_sql})")
end

#joined_alias_exists_subquery_inner_queryObject


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cancan/model_adapters/strategies/joined_alias_exists_subquery.rb', line 16

def joined_alias_exists_subquery_inner_query
  model_class
    .unscoped
    .select('1')
    .left_joins(joins)
    .where(*where_conditions)
    .where(
      "#{quoted_table_name}.#{quoted_primary_key} = " \
      "#{quoted_aliased_table_name}.#{quoted_primary_key}"
    )
    .limit(1)
end