0
votes

I have a simple database that has the following relation

Each Question has one Questiontype (3 different typs , such as Questiontype1 , Questiontype2 , Questiontype3 )

in Questiontype has question_id

  • Question.rb (Model)

class Question < ActiveRecord::Base belongs_to :questiontype1 belongs_to :questiontype2 belongs_to :questiontype3 end

  • Questiontype1.rb (Model)

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

  • show.json.rabl (I used Rabl)

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

However, when I get child from Questiontype1 , result is null

Can I solve this problem?

Sorry for my English , Thank you.

1
don't forget to accept the answer :)apneadiving

1 Answers

1
votes

The type of a question is an attribute of the question, not the other way around. So the Question should has_one :questiontype and the Questiontype should belongs_to :question.