Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Always use table and primary key to specify conditions #54

Closed
wants to merge 1 commit into from

2 participants

@aflatter

Hey there,

I'm using the *_conditions methods to construct queries for another model. #subtree_conditions is the only method that works fine because it uses #{table_name}.#{primary_key}. This is a single commit to fix the other methods.

I could not run your tests because of uninitialized constant Test::Unit::AutoRunner::Priority (NameError). I was too lazy to look into it, but I don't think that I broke anything ;-)

@StefanH StefanH referenced this pull request from a commit
Stefan Henzen Added table name to conditions, based on #54 by aflatter
closes #54
926d668
@StefanH StefanH closed this pull request from a commit
Stefan Henzen Added table name to conditions, based on #54 by aflatter
closes #54
926d668
@StefanH StefanH closed this in 926d668
@StefanH
Collaborator

Tnx for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 30, 2011
  1. @aflatter
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/ancestry/instance_methods.rb
View
12 lib/ancestry/instance_methods.rb
@@ -70,7 +70,7 @@ def ancestor_ids
end
def ancestor_conditions
- {self.base_class.primary_key => ancestor_ids}
+ {primary_key_with_table => ancestor_ids}
end
def ancestors depth_options = {}
@@ -82,7 +82,7 @@ def path_ids
end
def path_conditions
- {self.base_class.primary_key => path_ids}
+ {primary_key_with_table => path_ids}
end
def path depth_options = {}
@@ -150,7 +150,7 @@ def is_childless?
# Siblings
def sibling_conditions
- {self.base_class.ancestry_column => read_attribute(self.base_class.ancestry_column)}
+ {primary_key_with_table => read_attribute(self.base_class.ancestry_column)}
end
def siblings
@@ -184,7 +184,7 @@ def descendant_ids depth_options = {}
# Subtree
def subtree_conditions
- ["#{self.base_class.table_name}.#{self.base_class.primary_key} = ? or #{self.base_class.table_name}.#{self.base_class.ancestry_column} like ? or #{self.base_class.table_name}.#{self.base_class.ancestry_column} = ?", self.id, "#{child_ancestry}/%", child_ancestry]
+ ["#{primary_key_with_table} = ? or #{self.base_class.table_name}.#{self.base_class.ancestry_column} like ? or #{self.base_class.table_name}.#{self.base_class.ancestry_column} = ?", self.id, "#{child_ancestry}/%", child_ancestry]
end
def subtree depth_options = {}
@@ -225,6 +225,10 @@ def cast_primary_key(key)
end
end
+ def primary_key_with_table
+ "#{self.base_class.table_name}.#{self.base_class.primary_key}"
+ end
+
def primary_key_type
@primary_key_type ||= column_for_attribute(self.class.primary_key).type
end
Something went wrong with that request. Please try again.