# 2 or more parents, child

**URL:** <https://www.ruby-forum.com/t/2-or-more-parents-child/113487>\
**Category:** Rails\
**Created:** [August 31, 2007, 5:08pm UTC](https://www.ruby-forum.com/t/2-or-more-parents-child/113487 "2007-08-31T17:08:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [August 31, 2007, 5:08pm UTC](https://www.ruby-forum.com/t/2-or-more-parents-child/113487/1 "2007-08-31T17:08:02Z")

</div>

Hello,

Here’s what I hope to accomplish:

A task may have 0,1, or more parent tasks - for example, a task may be  
top-level, or a simple sub-task (1 parent), or a multi-purpose task  
(e.g.  
setting up automatic backup of the svn repository benefits both projectA  
and  
projectB [note that I’m treating projects as tasks, just bigger ones  
with  
more children]).

It may be relatively rare for a task to have more than one parent, so  
I’m  
not sure I want to complicate the entire system because of that. For  
example I might use a simple parent-child approach for tasks and then  
have a  
“tasks\_tasks” table to record supplemental parent-child relationships.  
Alternatively, I could just use “tasks\_tasks” to include all such  
relationships (and perhaps others, e.g. dependencies).

Any thoughts, guidance?

Thanks!

Marc

---

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [August 31, 2007, 8:47pm UTC](https://www.ruby-forum.com/t/2-or-more-parents-child/113487/2 "2007-08-31T20:47:29Z")

</div>

Check out acts\_as\_graph, it’ll handle multiple parents.

[http://blog.tammersaleh.com/pages/acts\_as\_graph](http://blog.tammersaleh.com/pages/acts_as_graph)

On 8/31/07, Marc B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Marc
> 
> >

–  
Joshua B.  
[http://www.linkedin.com/in/joshuabates](http://www.linkedin.com/in/joshuabates)

---

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [August 31, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/2-or-more-parents-child/113487/3 "2007-08-31T21:16:33Z")

</div>

Joshua B. wrote:

> Check out acts\_as\_graph, it’ll handle multiple parents.
> 
> [http://blog.tammersaleh.com/pages/acts\_as\_graph](http://blog.tammersaleh.com/pages/acts_as_graph)

That’s a really good solution for what the poster is asking. I wrote an  
acts\_as\_graph as well, and it’s under [http://gratr.rubyforge.org](http://gratr.rubyforge.org).

The difference here is that Tammersaleh’s fits 95% of most common usage  
and looks like it does it cleanly and more “Railish”. The one I wrote  
ties into advanced graph algorithms so crazy things like condensation  
graphs and sub graphs determinations are possible. Also there is a rich  
set of graph search algorithms in gratr.

Personally, after looking thorough tammersaleh’s code I’d use that if it  
meets your needs. If you need some advanced graph manipulation, look at  
gratr.
