Sha256: a90b37fb95ef5fc09f34b5f66557104b85404efea344bda3f4a097c0c8ad3efb
Contents?: true
Size: 739 Bytes
Versions: 7
Compression:
Stored size: 739 Bytes
Contents
module Searchlogic module Condition class DescendantOf < Tree def to_conditions(value) # Wish I knew how to do this in SQL root = (value.is_a?(klass) ? value : klass.find(value)) rescue return strs = [] subs = [] all_children_ids(root).each do |child_id| strs << "#{quoted_table_name}.#{quote_column_name(klass.primary_key)} = ?" subs << child_id end [strs.join(" OR "), *subs] end private def all_children_ids(record) ids = record.children.collect { |child| child.send(klass.primary_key) } record.children.each { |child| ids += all_children_ids(child) } ids end end end end
Version data entries
7 entries across 7 versions & 1 rubygems