Skip to content

Commit

Permalink
Cope with classes that have default scope
Browse files Browse the repository at this point in the history
(also, more idiomatic activerecord 3)
  • Loading branch information
cluesque committed Feb 20, 2013
1 parent 0645cd7 commit cdd7cbc
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/activerecord_constraint_handlers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ def pg_attribute_constant
# Turns out, we don't really use this...
def pg_class
ActiveRecord::Base.logger.debug("pg_class")
@pg_class ||= pg_class_constant.find_by_relname(table_name)
@pg_class ||= pg_class_constant.unscoped.find_by_relname(table_name)
end

# Find the constraints for this model / table
def pg_constraints
ActiveRecord::Base.logger.debug("pg_constraints")
if @pg_constraints.nil?
@pg_constraints = pg_constraint_constant.find(:all,
:joins => :conrel,
:conditions => { :pg_class => { :relname => table_name }})
@pg_constraints = pg_constraint_constant.unscoped.joins(:conrel).where(:pg_class => { :relname => table_name }).all
@pg_constraint_hash = Hash.new
@pg_constraints.each { |c|
ActiveRecord::Base.logger.debug("Adding '#{c.conname}' to constraint_hash")
Expand All @@ -120,9 +118,7 @@ def pg_constraint_hash
def pg_attributes
ActiveRecord::Base.logger.debug("pg_attributes")
if @pg_attributes.nil?
@pg_attributes = pg_attribute_constant.find(:all,
:joins => :attrel,
:conditions => { :pg_class => { :relname => table_name }})
@pg_attributes = pg_attribute_constant.unscoped.joins(:attrel).where(:pg_class => { :relname => table_name })
@pg_attribute_hash = Hash.new
@pg_attributes.each { |a| @pg_attribute_hash[a.attnum] = a }
end
Expand Down

0 comments on commit cdd7cbc

Please sign in to comment.