如何在 Rails 中通过关联对 has_many 进行关联?
警告:我可能有错误的“问题陈述”,但事实是:
一个营销活动有很多联系人。
一个营销活动有很多电子邮件。
因此,一个联系人通过一个营销活动拥有许多电子邮件。
一封电子邮件可以通过一个营销活动拥有多个联系人。
每个联系人-电子邮件对都有其自己唯一的状态(状态 1、状态 2 等)。
每个状态(对于联系人-电子邮件对)都有其自己的用户。
我不知道如何对状态或用户进行建模。目前最直接的挑战是地位。
(见下图)
Warning: I may have the wrong 'problem statement' but here it goes:
A Campaign has many Contacts.
A Campaign has many Emails.
Therefore, a Contact has many Emails through a Campaign.
And an Email can have many Contacts through a Campaign.
Each Contact-Email pair has its own unique Status (status1, status2, etc).
Each Status (for a Contact-Email pair) will have its own User.
I do not know how to model Status, or User. Currently the immediate challenge is Status.
(see diagram below)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的解决方案假设状态可以表示为字符串。
添加电子邮件地址到联系人:
或
或创建多个:
编辑 2
ContactEmail 的嵌套资源。
ContactEmail 的 URL
该 URL 没有电子邮件 ID。您可以将 email_id 作为查询参数传递,即
在您的 ContactEmailsController 中:
在您的视图中将
email_id
设置为隐藏字段。在
create
方法中执行保存。Solution below is assuming that status can be represented as a string.
Adding emails to contact:
OR
OR create multiple:
Edit 2
Nested resources for ContactEmail.
URL for ContactEmail
The URL does not have the email id. You can pass the email_id as a query parameter, i.e.
In your ContactEmailsController:
In your view set
email_id
as hidden field.In the
create
method perform the save.