0

如果没有以下内容,则无法在 mongoid 中实现提供的方案has_ through

用户有很多帖子,属于很多项目,并且根据参与的一些项目,属于一些版块,可以是项目中的管理员

部分有许多项目、用户和帖子

项目有很多帖子和用户,属于很多部分,有些用户是这里的管理员(belong关系?)

帖子属于一个用户,项目和许多部分

如何?

对所有事物都使用多态关联?

我的代码: http: //pastebin.com/sFzs1FD8

4

1 回答 1

0

自己做的:)

# Models:
class User
  has_and_belongs_to_many :projects
  has_many :posts, inverse_of: :author
end

class Project
  has_and_belongs_to_many :users
  has_many :posts, inverse_of: :project
end

class Post
  belongs_to :project, inverse_of: :posts
  belongs_to :author, class_name: 'User'
end
于 2013-05-31T15:46:32.477 回答