2012-02-11 36 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