与SAME对象类型的has_one和has_many关系

时间:2016-03-11 10:16:51

标签: ruby-on-rails polymorphism has-many has-one

我正在使用Ruby on Rails编写网站,我有许多多态关系,但我想要两个特定的关系:

A has_one C
B has_many C

当我使用Rails为C生成多态代码时,似乎has_one A / C关系需要使用form的函数:

A.C... e.g.
@c = @poly.c.find(params[:id])

虽然has_many B / C关系需要表格

的功能
B.Cs... ** Note the plural for B **
@c = @poly.cs.find(params[:id])

那么有没有办法做我想做或做的事情我必须使A / C关系has_many并添加额外的检查以确保它像has_one一样?

0 个答案:

没有答案