Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Always use table and primary_key to specify conditions

  • Loading branch information...
commit 97dfaf9c41d3a203657a336a46cd481c89ee6ee0 1 parent 59d155e
@aflatter authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.