我无法决定如何使用rails关联建模以下内容。Rails关联+继承
的UML将类似于下面:
----------------
| CRITERIA |
----------------
|
|*
----------------
| CONTROLS | <___
---------------- \
^ \
| \
------------------- -------------------
| SCALE CONTROL | | TEXT CONTROL | .....
------------------- -------------------
-The各种控件具有完全不同的属性,这样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中实现类似上面的内容?
相关:http://stackoverflow.com/questions/5022802/multi-table-inheritance-with-rails-3 – Reactormonk 2013-04-29 00:14:46