我无法决定如何使用 rails 关联来建模以下内容。
UML 如下所示:
----------------
| CRITERIA |
----------------
|
|*
----------------
| CONTROLS | <___
---------------- \
^ \
| \
------------------- -------------------
| SCALE CONTROL | | TEXT CONTROL | .....
------------------- -------------------
- 各种控件具有完全不同的属性,因此 STI 似乎是一个糟糕的选择。
- 用户可以为每个标准指定任意数量的控件。
我想做类似以下的事情:
Criteria
has_many :controls
ScaleControl
belongs_to :criteria, as: control
TextControl
belongs_to :criteria, as: control
并且能够按照以下方式进行查询:
criteria.controls
# displays all controls (text, scale, etc.)
criteria.controls.each { ... }
到目前为止我所看到的:
-RailsCasts 关于多态关联的剧集,似乎这不是一个好的用例。
- 数十个铁路协会在这里发帖,但没有找到任何直接相关的内容。
-Rails 文档。
在 Rails 中实现上述内容是否有任何通用模式?