у меня есть 4 таблицы: вопросы, ответы, пользователи и запросы (таблица отношений между ними)
this my_controller
def index
question_id = params[:id].to_i
question = Question.find(question_id)
@answers = question.answers
respond_to do |format|
format.ext_json { render :json => @answers.to_ext_json(:class =>
Answer) }
end
end
У меня есть сетки в extjs, когда янажмите на строку, я получу ответы на вопрос, который я только что выбрал, COOL.Но мне нужно вставить в эту информацию электронную почту людей (магазины электронной почты в таблице пользователей).Теперь у меня есть это:
| id | answer |
1 | lala
2 | lalala2
но мне нужно это:
| id | answer | email
1 | lala | alal@sa.com
2 | lal2 | asasa@was.net
пс
users (table): id, email
questions (table): id, text
inquiries: question_id, user_id
answers: inquiry_id, text
Модель пользователей:
has_many :inquiries
has_many :questions, :through => :inquiries
has_many :answers, :through => :inquiries
модель вопроса:
has_many :inquiries, :dependent => :destroy
has_many :answers, :through => :inquiries, :dependent => :destroy
модель ответа
belongs_to :inquiry
belongs_to :question
модель запроса
belongs_to :question
belongs_to :users
has_one :answer, :dependent => :destroy