Rails groups / user members associations best practices
i.e.: group1 has members 1, 2 and 3
group2 has members 4, 5 and 6 group3 has members 7, 8 and 9also, each of the membe开发者_JAVA技巧rs can submit posts to their group's directory.
I'm trying to figure out the best logic to approach this with in terms of database management, etc. Is it as simple as creating a groups model, which has_many members, which has_many posts and going from there?
I guess I'm just worried that things will eventually start to get jumbled up with the group login, and the individual user logins, etc.
Thanks for any help with this, I realize it is quite a broad question at this point.I would model it as follows:
class Group < ActiveRecord::Base
has_many :members
has_many :posts, :through => :members
end
class Member < ActiveRecord::Base
belongs_to :group
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :member
end
精彩评论