Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When generating this join, rails seems to munge it, but reversing the

join order fixes it.  This is the SQL (Postgres) generated otherwise:

INNER JOIN sanction_roles AS sanction_permissionable_role_query ON
'Team' AND = sanction_permissionable_role_query.permissionable_type
  • Loading branch information...
commit e4e22f07baefd4c95296aad2969726bc60360b72 1 parent 81eaecc
@crystalneth crystalneth authored
View
10 lib/sanction/permissionable/base.rb
@@ -14,8 +14,9 @@ def self.extended(base)
returned_scope = {:conditions => ["#{ROLE_ALIAS}.permissionable_type = ?", base.name.to_s], :select => "DISTINCT #{base.table_name}.*"}
unless already_joined
- returned_scope.merge({:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON #{ROLE_ALIAS}.permissionable_type = '#{base.name.to_s}' AND
- (#{ROLE_ALIAS}.permissionable_id = #{base.table_name}.#{base.primary_key.to_s} OR #{ROLE_ALIAS}.permissionable_id IS NULL)"})
+ returned_scope.merge({:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON (
+ (#{ROLE_ALIAS}.permissionable_id = #{base.table_name}.#{base.primary_key.to_s} OR #{ROLE_ALIAS}.permissionable_id IS NULL)
+ AND #{ROLE_ALIAS}.permissionable_type = '#{base.name.to_s}')"})
end
}
@@ -24,8 +25,9 @@ def self.extended(base)
returned_scope = {:conditions => ["#{klass_instance.class.table_name}.#{klass_instance.class.primary_key.to_s} = ?", klass_instance.id], :select => "DISTINCT #{klass_instance.class.table_name}.*"}
unless already_joined
- returned_scope.merge({:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON #{ROLE_ALIAS}.permissionable_type = '#{klass_instance.class.name.to_s}' AND
- (#{ROLE_ALIAS}.permissionable_id = '#{klass_instance.id}' OR #{ROLE_ALIAS}.permissionable_id IS NULL)"})
+ returned_scope.merge({:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON
+ (#{ROLE_ALIAS}.permissionable_id = '#{klass_instance.id}' OR #{ROLE_ALIAS}.permissionable_id IS NULL)
+ AND #{ROLE_ALIAS}.permissionable_type = '#{klass_instance.class.name.to_s}'"})
end
}
end
View
10 lib/sanction/principal/base.rb
@@ -14,8 +14,9 @@ def self.extended(base)
returned_scope = {:conditions => ["#{ROLE_ALIAS}.principal_type = ?", base.name.to_s], :select => "DISTINCT #{base.table_name}.*"}
unless already_joined
- returned_scope.merge( {:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON #{ROLE_ALIAS}.principal_type = '#{base.name.to_s}' AND
- (#{ROLE_ALIAS}.principal_id = #{base.table_name}.#{base.primary_key.to_s} OR #{ROLE_ALIAS}.principal_id IS NULL)"} )
+ returned_scope.merge( {:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON
+ (#{ROLE_ALIAS}.principal_id = #{base.table_name}.#{base.primary_key.to_s} OR #{ROLE_ALIAS}.principal_id IS NULL)
+ AND #{ROLE_ALIAS}.principal_type = '#{base.name.to_s}'"} )
end
}
@@ -24,8 +25,9 @@ def self.extended(base)
returned_scope = {:conditions => ["#{klass_instance.class.table_name}.#{klass_instance.class.primary_key.to_s} = ?", klass_instance.id], :select => "DISTINCT #{klass_instance.class.table_name.to_s}.*"}
unless already_joined
- returned_scope.merge({:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON #{ROLE_ALIAS}.principal_type = '#{klass_instance.class.name.to_s}' AND
- (#{ROLE_ALIAS}.principal_id = '#{klass_instance.id}' OR #{ROLE_ALIAS}.principal_id IS NULL)"})
+ returned_scope.merge({:joins => "INNER JOIN #{Sanction::Role.table_name} AS #{ROLE_ALIAS} ON
+ (#{ROLE_ALIAS}.principal_id = '#{klass_instance.id}' OR #{ROLE_ALIAS}.principal_id IS NULL) AND
+ #{ROLE_ALIAS}.principal_type = '#{klass_instance.class.name.to_s}'"})
end
}
end

0 comments on commit e4e22f0

Please sign in to comment.
Something went wrong with that request. Please try again.