D-Nice
D-Nice

Reputation: 4870

Giving an object multiple parents with Ancestry gem

I have an object Person that has two parent Persons. I want to be able to receive an array of Person objects when I do my_person.parents (currently undefined). I'm currently using the ancestry gem, which seems to limit you to a single parent. Is there any way that I can accomplish what I want with the gem, or does anyone have any other suggestions?

Thanks

Upvotes: 2

Views: 1490

Answers (2)

kbrock
kbrock

Reputation: 1017

Ancestry only supports 1 parent.

The parents are stored in a string of type

ancestry = "/grandparent_id/parent_id"

So there is only 1 slot for a parent. see https://github.com/stefankroes/ancestry/issues/94

I'm thinking ancestry may not be the best solution for you. May want to try out colsure trees or another plugin

Upvotes: 0

robinst
robinst

Reputation: 31407

That's essentially a many-to-many relationship (Person has and belongs to many parents). You need a has_and_belongs_to_many relationship from Person to itself, with a join table.

See here for an example: ActiveRecord relationships for a join table linking two records of the same table?

Upvotes: 3

Related Questions