Working on a forum in rails, but I am stumped on the storing/
retrieving of forum posts.
Using Acts_as_Tree, but can''t figure out how to query my model to get
a list of the most recent posts in every thread.
Model Post
id
parent_id
post
created_at
This gets the parent of each thread...
parent_posts = Post.find(:all, :conditions => "parent_id is
NULL")
This gets all of the posts in a thread that are siblings...
sibling_posts = Post.children.find(parent_post)
Any ideas please?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
acts_as_nested_set That allows you to get all children in one query. On Dec 4, 2007, at 7:29 PM, yachtman wrote:> > Working on a forum in rails, but I am stumped on the storing/ > retrieving of forum posts. > > Using Acts_as_Tree, but can''t figure out how to query my model to get > a list of the most recent posts in every thread. > > Model Post > id > parent_id > post > created_at > > This gets the parent of each thread... > parent_posts = Post.find(:all, :conditions => "parent_id is NULL") > > This gets all of the posts in a thread that are siblings... > sibling_posts = Post.children.find(parent_post) > > Any ideas please? > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
s.ross - Seems like this is overly-complicated since it utilizes > root > children > children''s children etc... When in my case, it''s either: #1: root > child > child''s child > child''s child''s child (Each initial post is a root, and each reply (child) is a reply to the last child or #2: root > children (Each initial post is the root, and the replies with be the timestamped children) If I go with #2, then at most I have two layers - Roots (Each initial post in the forum) and many direct children of each root (the timestamped--which will give me the order--replies). The overhead seems high with acts_as_nested_set.... On Dec 5, 12:52 pm, "s.ross" <cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> acts_as_nested_set > > That allows you to get all children in one query. > > On Dec 4, 2007, at 7:29 PM, yachtman wrote: > > > > > Working on a forum in rails, but I am stumped on the storing/ > > retrieving of forum posts. > > > Using Acts_as_Tree, but can''t figure out how to query my model to get > > a list of the most recent posts in every thread. > > > Model Post > > id > > parent_id > > post > > created_at > > > This gets the parent of each thread... > > parent_posts = Post.find(:all, :conditions => "parent_id is NULL") > > > This gets all of the posts in a thread that are siblings... > > sibling_posts = Post.children.find(parent_post) > > > Any ideas please?#S--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If you were modeling this (your scenario 1), you might use a linked
list or doubly linked list. Right? Would acts_as_list work? That
would preserve order and of course the scope of the list would be the
thread id or something sensible like that.
Your scenario 2 is something of a bag. No real positional
relationship implied, you handle the ordering based on the data.
Perhaps acts_as_tree is not what you were looking for. The only
reason I suggested aans is because if has proven effective for me at
partitioning threaded topical discussions where there is not a strict
linear descendency. For example:
- (Poster 1) when is rails 2.0 gonna be released
- (Poster 2) re: when is rails 2.0 gonna be released
- (Poster 1) re: when is rails 2.0 gonna be released
- (Poster 3) re: when is rails 2.0 gonna be released
This is more the slashdot model and requires a bit more tracking of
who replied to whom within a thread.
-s
On Dec 4, 2007, at 9:17 PM, yachtman wrote:
>
> s.ross - Seems like this is overly-complicated since it utilizes >
> root > children > children''s children etc...
>
> When in my case, it''s either:
> #1: root > child > child''s child > child''s
child''s child (Each
> initial post is a root, and each reply (child) is a reply to the last
> child
> or
> #2: root > children (Each initial post is the root, and the replies
> with be the timestamped children)
>
> If I go with #2, then at most I have two layers - Roots (Each initial
> post in the forum) and many direct children of each root (the
> timestamped--which will give me the order--replies).
>
> The overhead seems high with acts_as_nested_set....
>
> On Dec 5, 12:52 pm, "s.ross"
<cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> acts_as_nested_set
>>
>> That allows you to get all children in one query.
>>
>> On Dec 4, 2007, at 7:29 PM, yachtman wrote:
>>
>>
>>
>>> Working on a forum in rails, but I am stumped on the storing/
>>> retrieving of forum posts.
>>
>>> Using Acts_as_Tree, but can''t figure out how to query my
model to
>>> get
>>> a list of the most recent posts in every thread.
>>
>>> Model Post
>>> id
>>> parent_id
>>> post
>>> created_at
>>
>>> This gets the parent of each thread...
>>> parent_posts = Post.find(:all, :conditions =>
"parent_id is
>>> NULL")
>>
>>> This gets all of the posts in a thread that are siblings...
>>> sibling_posts = Post.children.find(parent_post)
>>
>>> Any ideas please?#S
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---