I'm currently using ancestry gem to do a hierarchy list of my "posts", but I need to have the option to a child have multiple parents, and with ancestry I can't do that. You guys have any solution? Adapting ancestry with other gem or using other gem instead. Thanks
            Asked
            
        
        
            Active
            
        
            Viewed 755 times
        
    1 Answers
0
            
            
        Use HABATM association
What you want to achieve is essentially has_and_belongs_to_many relationship. You can create a relationship on yourself and that should do the trick. If you need help on how to do this with HABTM association, here is a SO answer that shows how.
class Post < ActiveRecord::Base
  has_and_belongs_to_many :children, 
              class_name: "Post", 
              join_table: :children, 
              foreign_key: :post_id, 
              association_foreign_key: :child_post_id
end
Alternatively, use a gem
You can use acts-as-taggable-on gem to tag your posts. It would be better if you create a model or enum that holds your tags, so that you don't mistype them while tagging.
You can query your posts like this:
Post.tagged_with(["ruby", "rails"], :any => true)
- 
                    this is for a single table? – terrorista Jun 23 '16 at 13:43
- 
                    Yeap, it is for a single table. – Uzbekjon Jun 23 '16 at 13:44
 
     
    