Acts as Tree with Multiple Models
- by Joe
I've got several models that I'd like to relate together hierarchically. For simplicity's sake, let's say I've got these three:
class Group < ActiveRecord::Base
acts_as_tree
has_many :users
end
class User < ActiveRecord::Base
acts_as_tree
belongs_to :group
has_many :posts
end
class Post < ActiveRecord::Base
acts_as_tree
belongs_to :user
end
Under the current acts_as_tree, each node can individually can relate hierarchically to other nodes provided they are of the same type. What I'd like is to remove this restriction on type identity, so that SomePost.parent could have a User or a Post as its' parent, and that SomeUser.parent could have another user or a group as its parent.
Any thoughts?