Permalink
Browse files

Removed superfluous backticks that were causing problems with PostgreSQL

  • Loading branch information...
1 parent e3ba4d2 commit 0f590edb0274c1853fa397da039990970667c962 @redinger redinger committed Oct 13, 2009
@@ -4,26 +4,26 @@ module Base
def self.extended(base)
base.class_eval %q{
has_many :permissionable_roles, :as => :permissionable, :class_name => "Sanction::Role",
- :finder_sql => 'SELECT * FROM `roles` WHERE `roles`.`permissionable_type` = "#{self.class.name.to_s}" AND (`roles`.`permissionable_id` = "#{id}" OR `roles`.`permissionable_id` IS NULL)'
+ :finder_sql => 'SELECT * FROM roles WHERE roles.permissionable_type = "#{self.class.name.to_s}" AND (roles.permissionable_id = "#{id}" OR roles.permissionable_id IS NULL)'
}
base.named_scope :as_permissionable_self, lambda {
already_joined = Sanction::Extensions::Joined.already? base, ROLE_ALIAS
- returned_scope = {:conditions => ["`#{ROLE_ALIAS}`.`permissionable_type` = ?", base.name.to_s], :select => "DISTINCT `#{base.table_name}`.*"}
+ 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 `roles` AS `#{ROLE_ALIAS}` ON `#{ROLE_ALIAS}`.`permissionable_type` = '#{base.name.to_s}' AND
- (`#{ROLE_ALIAS}`.`permissionable_id` = `#{base.table_name}`.`id` OR `#{ROLE_ALIAS}`.`permissionable_id` IS NULL)"})
+ returned_scope.merge({:joins => "INNER JOIN roles AS #{ROLE_ALIAS} ON #{ROLE_ALIAS}.permissionable_type = '#{base.name.to_s}' AND
+ (#{ROLE_ALIAS}.permissionable_id = #{base.table_name}.id OR #{ROLE_ALIAS}.permissionable_id IS NULL)"})
end
}
base.named_scope :as_permissionable, lambda {|klass_instance|
already_joined = Sanction::Extensions::Joined.already? base, ROLE_ALIAS
- returned_scope = {:conditions => ["`#{klass_instance.class.table_name}`.`id` = ?", klass_instance.id], :select => "DISTINCT `#{klass_instance.class.table_name}`.*"}
+ returned_scope = {:conditions => ["#{klass_instance.class.table_name}.id = ?", klass_instance.id], :select => "DISTINCT #{klass_instance.class.table_name}.*"}
unless already_joined
- returned_scope.merge({:joins => "INNER JOIN `roles` 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 roles 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)"})
end
}
end
@@ -10,16 +10,16 @@ module ClassMethods
def self.extended(base)
base.named_scope :for_scope_method, lambda {|*args|
if args.include? Sanction::Role::Definition::ANY_TOKEN
- {:conditions => ["`#{ROLE_ALIAS}`.`principal_type` IS NOT NULL"]}
+ {:conditions => ["#{ROLE_ALIAS}.principal_type IS NOT NULL"]}
else
args.map {|a| raise Sanction::Role::Error::UnknownPrincipal.new("Unknown principal: #{a}") unless Sanction::Role::Definition.valid_principal? a }
conds = []
args.each do |arg|
if arg.is_a? Class
- conds << ["`#{ROLE_ALIAS}`.`principal_type` = ?", arg.to_s]
+ conds << ["#{ROLE_ALIAS}.principal_type = ?", arg.to_s]
else
- conds << ["`#{ROLE_ALIAS}`.`principal_type` = ? AND (`#{ROLE_ALIAS}`.`principal_id` = ? OR `#{ROLE_ALIAS}`.`principal_id` IS NULL)", arg.class.name.to_s, arg.id]
+ conds << ["#{ROLE_ALIAS}.principal_type = ? AND (#{ROLE_ALIAS}.principal_id = ? OR #{ROLE_ALIAS}.principal_id IS NULL)", arg.class.name.to_s, arg.id]
end
end
conditions = conds.map { |c| base.merge_conditions(c) }.join(" OR ")
@@ -28,14 +28,14 @@ def self.extended(base)
}
base.named_scope :for_all_single_argument, lambda {|arg|
if arg == Sanction::Role::Definition::ANY_TOKEN
- {:conditions => ["`#{ROLE_ALIAS}`.`principal_type` IS NOT NULL"]}
+ {:conditions => ["#{ROLE_ALIAS}.principal_type IS NOT NULL"]}
else
raise Sanction::Role::Error::UnknownPrincipal.new("Unknown principal: #{arg}") unless Sanction::Role::Definition.valid_principal? ar
if arg.is_a? Class
- {:conditions => ["`#{ROLE_ALIAS}`.`principal_type` = ? AND `#{ROLE_ALIAS}`.`principal_id` IS NULL", arg.name.to_s]}
+ {:conditions => ["#{ROLE_ALIAS}.principal_type = ? AND #{ROLE_ALIAS}.principal_id IS NULL", arg.name.to_s]}
else
- {:conditions => ["`#{ROLE_ALIAS}`.`principal_type` = ? AND (`#{ROLE_ALIAS}`.`principal_id` = ? OR `#{ROLE_ALIAS}`.`principal_id` IS NULL)", arg.class.name.to_s, arg.id]}
+ {:conditions => ["#{ROLE_ALIAS}.principal_type = ? AND (#{ROLE_ALIAS}.principal_id = ? OR #{ROLE_ALIAS}.principal_id IS NULL)", arg.class.name.to_s, arg.id]}
end
end
}
@@ -9,7 +9,7 @@ module ClassMethods
def self.extended(base)
base.named_scope :with_scope_method, lambda {|*role_names|
if role_names.include? Sanction::Role::Definition::ANY_TOKEN
- {:conditions => ["`" + ROLE_ALIAS + "`.`name` IS NOT NULL"]} if role_names.include? :any
+ {:conditions => [ROLE_ALIAS + ".name IS NOT NULL"]} if role_names.include? :any
else
role_names.map! do |role_or_permission|
roles_to_look_for = []
@@ -25,7 +25,7 @@ def self.extended(base)
role_names.flatten!
role_names.uniq!
- conditions = role_names.map {|r| base.merge_conditions(["`#{ROLE_ALIAS}`.`name` = ?", r.to_s])}.join(" OR ")
+ conditions = role_names.map {|r| base.merge_conditions(["#{ROLE_ALIAS}.name = ?", r.to_s])}.join(" OR ")
{:conditions => conditions}
end
}
@@ -4,26 +4,26 @@ module Base
def self.extended(base)
base.class_eval %q{
has_many :principal_roles, :as => :principal, :class_name => "Sanction::Role",
- :finder_sql => 'SELECT * FROM `roles` WHERE `roles`.`principal_type` = "#{self.class.name.to_s}" AND (`roles`.`principal_id` = "#{id}" OR `roles`.`principal_id` IS NULL)'
+ :finder_sql => 'SELECT * FROM roles WHERE roles.principal_type = "#{self.class.name.to_s}" AND (roles.principal_id = "#{id}" OR roles.principal_id IS NULL)'
}
base.named_scope :as_principal_self, lambda {
already_joined = Sanction::Extensions::Joined.already? base, ROLE_ALIAS
- returned_scope = {:conditions => ["`#{ROLE_ALIAS}`.`principal_type` = ?", base.name.to_s], :select => "DISTINCT `#{base.table_name}`.*"}
+ 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 `roles` AS `#{ROLE_ALIAS}` ON `#{ROLE_ALIAS}`.`principal_type` = '#{base.name.to_s}' AND
- (`#{ROLE_ALIAS}`.`principal_id` = `#{base.table_name}`.`id` OR `#{ROLE_ALIAS}`.`principal_id` IS NULL)"} )
+ returned_scope.merge( {:joins => "INNER JOIN roles AS #{ROLE_ALIAS} ON #{ROLE_ALIAS}.principal_type = '#{base.name.to_s}' AND
+ (#{ROLE_ALIAS}.principal_id = #{base.table_name}.id OR #{ROLE_ALIAS}.principal_id IS NULL)"} )
end
}
base.named_scope :as_principal, lambda {|klass_instance|
already_joined = Sanction::Extensions::Joined.already? base, ROLE_ALIAS
- returned_scope = {:conditions => ["`#{klass_instance.class.table_name}`.`id` = ?", klass_instance.id], :select => "DISTINCT `#{klass_instance.class.table_name.to_s}`.*"}
+ returned_scope = {:conditions => ["#{klass_instance.class.table_name}.id = ?", klass_instance.id], :select => "DISTINCT #{klass_instance.class.table_name.to_s}.*"}
unless already_joined
- returned_scope.merge({:joins => "INNER JOIN `roles` 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 roles 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)"})
end
}
end
@@ -10,7 +10,7 @@ module ClassMethods
def self.extended(base)
base.named_scope :has_scope_method, lambda {|*role_names|
if role_names.include? Sanction::Role::Definition::ANY_TOKEN
- {:conditions => ["`" + ROLE_ALIAS + "`.`name` IS NOT NULL"]}
+ {:conditions => [ROLE_ALIAS + ".name IS NOT NULL"]}
else
role_names.map! do |role_or_permission|
roles_to_look_for = []
@@ -26,7 +26,7 @@ def self.extended(base)
role_names.flatten!
role_names.uniq!
- conditions = role_names.map {|r| base.merge_conditions(["`#{ROLE_ALIAS}`.`name` = ?", r.to_s])}.join(" OR ")
+ conditions = role_names.map {|r| base.merge_conditions(["#{ROLE_ALIAS}.name = ?", r.to_s])}.join(" OR ")
{:conditions => conditions}
end
}
@@ -24,16 +24,16 @@ module ClassMethods
def self.extended(base)
base.named_scope :over_scope_method, lambda {|*args|
if args.include? Sanction::Role::Definition::ANY_TOKEN
- {:conditions => ["`#{ROLE_ALIAS}`.`permissionable_type` IS NOT NULL"]}
+ {:conditions => ["#{ROLE_ALIAS}.permissionable_type IS NOT NULL"]}
else
args.map {|a| raise Sanction::Role::Error::UnknownPermissionable.new("Unknown permissionable: #{a}") unless Sanction::Role::Definition.valid_permissionable? a }
conds = []
args.each do |arg|
if arg.is_a? Class
- conds << ["`#{ROLE_ALIAS}`.`permissionable_type` = ?", arg.name.to_s] # Need id = nil here?
+ conds << ["#{ROLE_ALIAS}.permissionable_type = ?", arg.name.to_s] # Need id = nil here?
else
- conds << ["`#{ROLE_ALIAS}`.`permissionable_type` = ? AND (`#{ROLE_ALIAS}`.`permissionable_id` = ? OR `#{ROLE_ALIAS}`.`permissionable_id` IS NULL)", arg.class.name.to_s, arg.id]
+ conds << ["#{ROLE_ALIAS}.permissionable_type = ? AND (#{ROLE_ALIAS}.permissionable_id = ? OR #{ROLE_ALIAS}.permissionable_id IS NULL)", arg.class.name.to_s, arg.id]
end
end
conditions = conds.map { |c| base.merge_conditions(c) }.join(" OR ")
@@ -42,14 +42,14 @@ def self.extended(base)
}
base.named_scope :over_all_single_argument, lambda {|arg|
if arg == Sanction::Role::Definition::ANY_TOKEN
- {:conditions => ["`#{ROLE_ALIAS}`.`permissionable_type` IS NOT NULL"]}
+ {:conditions => ["#{ROLE_ALIAS}.permissionable_type IS NOT NULL"]}
else
raise Sanction::Role::Error::UnknownPermissionable.new("Unknown permissionable: #{arg}") unless Sanction::Role::Definition.valid_permissionable? arg
if arg.is_a? Class
- {:conditions => ["`#{ROLE_ALIAS}`.`permissionable_type` = ? AND `#{ROLE_ALIAS}`.`permissionable_id` IS NULL", arg.name.to_s]}
+ {:conditions => ["#{ROLE_ALIAS}.permissionable_type = ? AND #{ROLE_ALIAS}.permissionable_id IS NULL", arg.name.to_s]}
else
- {:conditions => ["`#{ROLE_ALIAS}`.`permissionable_type` = ? AND (`#{ROLE_ALIAS}`.`permissionable_id` = ? OR `#{ROLE_ALIAS}`.`permissionable_id` IS NULL)", arg.class.name.to_s, arg.id]}
+ {:conditions => ["#{ROLE_ALIAS}.permissionable_type = ? AND (#{ROLE_ALIAS}.permissionable_id = ? OR #{ROLE_ALIAS}.permissionable_id IS NULL)", arg.class.name.to_s, arg.id]}
end
end
}

0 comments on commit 0f590ed

Please sign in to comment.