Hi, I have a tree like structure roughly like this:
class Node < ActiveRecord::Base
belongs_to :parent, :class_name => self.to_s, :foreign_key => 'parent_id'
has_many :children, :class_name => self.to_s, :foreign_key => 'parent_id', :dependent => :destroy
...
end
I can load all nodes that don't have a parent with this scope:
named_scope :not_child, :conditions => 'parent_id IS NULL'
But I also need to find nodes that don't have children but can have a parent and I am having a hard time with it. I guess I have to include children_events but then I am lost, I cannot use:
named_scope, :faulty_not_parent, :include => :children, :conditions => "node.parent_id IS NULL"