How to find the child and subchild of particular node in a tree in sql. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sat, Jul 5, 2008 at 4:42 PM, mrbless <mrbless-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How to find the child and subchild of particular node in a tree in sql.more data needed for intelligent answer.. -- http://lindsaar.net/ Rails, RSpec and Life blog.... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks I have resolve it. On Jul 5, 11:52 am, "Mikel Lindsaar" <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Jul 5, 2008 at 4:42 PM, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How to find the child and subchild of particular node in a tree in sql. > > more data needed for intelligent answer.. > > --http://lindsaar.net/ > Rails, RSpec and Life blog....--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
my database is like this: { id name subject body root_id parent_id lft rgt depth created_at updated_at } now what I want to do for the given id is I want to find all its children and sub children On Jul 5, 11:52 am, "Mikel Lindsaar" <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Jul 5, 2008 at 4:42 PM, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How to find the child and subchild of particular node in a tree in sql. > > more data needed for intelligent answer.. > > --http://lindsaar.net/ > Rails, RSpec and Life blog....--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I think this work ==========@posts=ForumPost.find_by_sql("SELECT parent.* "+ "FROM forum_posts AS node, "+ "forum_posts AS parent "+ "WHERE node.lft<=parent.lft AND node.rgt>=parent.rgt "+ "AND parent.root_id=node.root_id AND node.parent_id!=0 AND node.parent_id ="+params[:id]) ========== On Jul 5, 4:06 pm, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> my database is like this: > { > id > name > subject > body > root_id > parent_id > lft > rgt > depth > created_at > updated_at > > } > > now what I want to do for the given id is I want to find all its > children and sub children > On Jul 5, 11:52 am, "Mikel Lindsaar" <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Sat, Jul 5, 2008 at 4:42 PM, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > How to find the child and subchild of particular node in a tree in sql. > > > more data needed for intelligent answer.. > > > --http://lindsaar.net/ > > Rails, RSpec and Life blog....--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tell me guys whether this is absolutely fine or not as I haven''t checked it for all cases: ================================================================@post=ForumPost.find_by_sql("SELECT parent.* " + "FROM forum_posts AS node, "+ "forum_posts AS parent "+ "WHERE (node.lft<=parent.lft AND node.rgt>=parent.rgt " + "AND node.parent_id ="+params[:id]+ " AND parent.root_id=node.root_id AND node.parent_id!=0) or (parent.id="+params[:id]+ " AND node.id="+params[:id] +")") ======================= On Jul 7, 3:39 pm, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I think this work > ==========> @posts=ForumPost.find_by_sql("SELECT parent.* "+ > "FROM forum_posts AS node, "+ > "forum_posts AS parent "+ > "WHERE node.lft<=parent.lft AND node.rgt>=parent.rgt "+ > "AND parent.root_id=node.root_id AND node.parent_id!=0 AND > node.parent_id ="+params[:id]) > > ==========> > On Jul 5, 4:06 pm, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > my database is like this: > > { > > id > > name > > subject > > body > > root_id > > parent_id > > lft > > rgt > > depth > > created_at > > updated_at > > > } > > > now what I want to do for the given id is I want to find all its > > children and sub children > > On Jul 5, 11:52 am, "Mikel Lindsaar" <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Sat, Jul 5, 2008 at 4:42 PM, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > How to find the child and subchild of particular node in a tree in sql. > > > > more data needed for intelligent answer.. > > > > --http://lindsaar.net/ > > > Rails, RSpec and Life blog....--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---