Skip to content
代码片段 群组 项目
未验证 提交 4ff1aaed 编辑于 作者: Yorick Peterse's avatar Yorick Peterse
浏览文件

Document not using STI

上级 5819ca1a
No related branches found
No related tags found
无相关合并请求
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
- [Foreign Keys & Associations](foreign_keys.md) - [Foreign Keys & Associations](foreign_keys.md)
- [Serializing Data](serializing_data.md) - [Serializing Data](serializing_data.md)
- [Polymorphic Associations](polymorphic_associations.md) - [Polymorphic Associations](polymorphic_associations.md)
- [Single Table Inheritance](single_table_inheritance.md)
## i18n ## i18n
......
# Single Table Inheritance
**Summary:** don't use Single Table Inheritance (STI), use separate tables
instead.
Rails makes it possible to have multiple models stored in the same table and map
these rows to the correct models using a `type` column. This can be used to for
example store two different types of SSH keys in the same table.
While tempting to use one should avoid this at all costs for the same reasons as
outlined in the document ["Polymorphic Associations"](polymorphic_associations.md).
## Solution
The solution is very simple: just use a separate table for every type you'd
otherwise store in the same table. For example, instead of having a `keys` table
with `type` set to either `Key` or `DeployKey` you'd have two separate tables:
`keys` and `deploy_keys`.
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册