我是Rails的新手并设计一个域实体相关的应用程序,如:
以下是上述关系的映射
class Organization < ActiveRecord::Base
has_many :memberships
has_many :users, through: :memberships
end
class User < ActiveRecord::Base
has_many :memberships
has_many :organizations, through: :memberships
has_many :application_developers
has_many :applications, through: application_developers
end
class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :organization
end
class Application < ActiveRecord::Base
belongs_to :organization
has_many :application_developers
has_many :memberships, through: application_developers
end
class ApplicationDeveloper < ActiveRecord::Base
belongs_to :membership
belongs_to :application
end
有人可以验证上面的映射是否正确吗?请提供反馈。
如果你的设计比上面好,那将是非常值得的。
答案 0 :(得分:0)
如果组织中的每个用户都没有使用应用程序,并且只有某些用户,那么我会保留ApplicationDeveloper表,但是更改
belongs_to :membership
到
belongs_to :user