反向多态关联 [英] Reverse Polymorphic Associations

查看:147
本文介绍了反向多态关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父对象,邮政,它具有以下的儿童。

I have a parent object, Post, which has the following children.

has_one :link
has_one :picture
has_one :code

这些孩子是互斥的。

These children are mutually exclusive.

有没有办法使用反向多态关联,这样我就不必有link_id,picture_id和code_ID领域在我的岗位表?一个办法

Is there a way to use polymorphic associations in reverse so that I don't have to have link_id, picture_id, and code_id fields in my Post table?

推荐答案

我写了一个小要点展示如何做到这一点:
https://gist.github.com/1242485

I wrote up a small Gist showing how to do this: https://gist.github.com/1242485

这篇关于反向多态关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆