开发者

Rails groups / user members associations best practices

I'm pretty new to Ruby and Rails and I'm developing a web app that requires multiple groups, each of which has many members, but the groups and members are completely separate from one another.

i.e.: group1 has members 1, 2 and 3

group2 has members 4, 5 and 6

group3 has members 7, 8 and 9

also, 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜