2012-02-11 105 views
0

我有了下面的关系式的简单数据库Rails的一个一对多关系,结果为空

每个问题都有一个Questiontype(3不同typs,如Questiontype1,Questiontype2,Questiontype3)

在Questiontype已question_id

  • Question.rb(型号)

类问题<的ActiveRecord ::基地 belongs_to的:questiontype1 belongs_to的:questiontype2 belongs_to的:questiontype3 端

  • Questiontype1.rb(型号)

class Questiontype1 < ActiveRecord的::基地的has_many:疑问 :foreign_key => “question_id” 结束

  • show.json.rabl(I使用Rabl的)

对象@question属性:id child:questiontype1 => :questiontype1 do attributes:id end

然而,当我从Questiontype1得到孩子时,结果为空

我可以解决这个问题吗?

对不起,我的英文,谢谢。

+0

不要忘记接受答案:) – apneadiving 2012-02-11 13:51:12

回答

1

问题的类型是问题的属性,而不是相反。所以Questionhas_one :questiontypeQuestiontypebelongs_to :question

+0

非常感谢, 我解决了它。 – 2012-02-11 13:21:04

+0

如果这个问题解决了,你能接受吗? – twilson 2012-02-11 13:32:32