This could be a lot simpler than I think and I'm just missing something
obvious!


I'm working on a creative collaboration app whereby one user could
submit a Story and this can then be forked by another user and worked on
seperately. To acheive this I have a has_many association within the
same Story model as such:

class Story < ActiveRecord::Base

  has_many :forked_stories, :class_name => 'Story', :foreign_key =>
:parent_story_id

  belongs_to :parent_story

end

In this way if a single story is an original it's parent_story_id will
be nil. Similarly, if I call @story.forked_stories I can get a
collection of all the stories that have been forked from the current
one, or @story.parent_story will return the story from which it has been
forked.

What I want is to be able to return all the forked_stories and their
forked_stories for a given Story and I'm finding this very difficult
since they're all based on the same model. I keep running into dead
ends. If I can return them to a certain depth as well that'd be great,
so I've been trying to write a method that accepts a depth parameter but
the crazy loops are frying my brain.

Perhaps there's something I can do with routes that would solve the
problem?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to