0

次の関係を持つ単純なデータベースがあります

各 Question には 1 つの Questiontype があります ( Questiontype1 、 Questiontype2 、 Questiontype3 などの3 つの異なるタイプ)

Questiontype に question_id があります

  • Question.rb(モデル)

class 質問 < ActiveRecord::Base 所属先 :questiontype1 所属先 :questiontype2 所属先 :questiontype3 end

  • Questiontype1.rb (モデル)

class Questiontype1 < ActiveRecord::Base has_many :questions , :foreign_key => "question_id" end

  • show.json.rabl (私は Rabl を使用しました)

object @question attributes :id child :questiontype1 => :questiontype1 do attributes :id end

ただし、 Questiontype1 から子を取得すると、結果は null

この問題を解決できますか?

私の英語でごめんなさい、ありがとう。

4

1 に答える 1

1

質問のタイプは質問の属性であり、その逆ではありません。したがって、Questionすべきhas_one :questiontypeであり、Questiontypeすべきbelongs_to :questionです。

于 2012-02-11T13:07:11.023 に答える