定义Sti表的关联
,并且有三个表从此表继承为:
class Manager < User
has_many :projects
end
class Qa < User
has_many :bugs
end
class Developer < User
has_many :bugs
has_and_belongs_to_many :projects
end
project
and bug
表as:
class Bug < ApplicationRecord
belongs_to :developer
belongs_to :qa
belongs_to :project
end
class Project < ApplicationRecord
belongs_to :manager
has_many :bugs
has_and_belongs_to_many :developers
end
我有一个表用户 在数据库中,我正在使用STI用于Manager,QA和开发人员,但是如何定义与这三个表相对应的迁移?
I have a table User
and there are three tables that inherit from this table as:
class Manager < User
has_many :projects
end
class Qa < User
has_many :bugs
end
class Developer < User
has_many :bugs
has_and_belongs_to_many :projects
end
The project
and bug
tables are as:
class Bug < ApplicationRecord
belongs_to :developer
belongs_to :qa
belongs_to :project
end
class Project < ApplicationRecord
belongs_to :manager
has_many :bugs
has_and_belongs_to_many :developers
end
The User table exists in the database and I am using STI for Manager, QA and Developer but how do I define migrations corresponding to the associations of these three tables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我最终最终使用了STI。数据库迁移如下:
So, I ultimately ended up using STI. The database migrations are as under: