Permalink
Browse files

MATT + PETE: You should pull this one, this is core bug

that manifests when you have tables with columns with primary_keys that are not .id
  • Loading branch information...
1 parent 266f8b0 commit 2155367e816eaff94152814de72eaaa4cf1c3019 @joegoggins joegoggins committed with pjleonhardt Jan 28, 2010
Showing with 4 additions and 4 deletions.
  1. +2 −2 lib/sanction/permissionable/base.rb
  2. +2 −2 lib/sanction/principal/base.rb
@@ -15,14 +15,14 @@ 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 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)"})
+ (#{ROLE_ALIAS}.permissionable_id = #{base.table_name}.#{base.primary_key.to_s} 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}.#{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 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)"})
@@ -15,14 +15,14 @@ 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 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)"} )
+ (#{ROLE_ALIAS}.principal_id = #{base.table_name}.#{base.primary_key.to_s} 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}.#{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 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)"})

0 comments on commit 2155367

Please sign in to comment.