Closed hickscorp closed 4 years ago
Bump... Ended up rewriting the plugin completely. See https://github.com/hickscorp/active_record-acts_as ... I know, it's old.
@hickscorp sorry we weren't able to respond in a timely manner. Looking into making the ancestry column configurable so a node will be able to act as a node in multiple trees
Hello,
Before starting, i would like to point out that i'm aware of the various "multiple parents" threads as well as the limitations for this gem. My question is about a different thing.
Let's say you have a user model inside a genealogy application. Let's say that you also want to handle referrals between users without having to create a separate model. The ideal solution and the most DRY would be to be able to call has_ancestry two times, each time with a different column but which would also override the generated method names and logic behind Ancestry:
This would then allow for instance:
Is there any way to maintain multiple ancestry columns inside the same model? My educated guess would be that the gem does not allow this kind of thing, as most of the generated methods on the instances (.parent, .ancestry etc) do not allow to give options regarding the column name. If you think that this request may be an interesting feature (Eg: Maintaining a list of ancestry-enabled methods and fields and columns), how hard do you think it would be to generate methods prefixed (Eg
#{ column_name }_ancestry
and#{ column_name }_parent
)? What other kind of change would this require?Having looked at the source code, i noticed that class and instance methods are right now added with module inclusions, and i guess it would require a bit of refactoring to meta-programming to use some HEREDOC-based eval, containing definitions like
def #{ column_name }_parent
etc if more thanhas_ancestry
call was made, or if thehas_ancestry
call was made with a column specification. Would it be a feasible thing for this gem in the near future?A pointer regarding class_eval would be the answer from Dr. Johnny Mohawk on this SO post.
Else, do you know any gem that might support what i'm trying to achieve? Thanks!