Mysql is wrong or rails 2.0.2 is wrong?

I have 3 tables want to join.

questions: id, question_category_id, content
answers: id, question_id, created_at, content, person_id
question_categories: id, name, created_at

and now I do this on rails 2.0.2:
@myanswers = Answer.find_by_sql("
SELECT answers.*, question_categories.name AS
question_category_name
FROM answers
JOIN questions on answers.question_id=questions.id
JOIN question_categories on questions.question_category_id =
question_categories.id
WHERE answers.person_id = 12
ORDER BY answers.created_at DESC
")
puts @myanswers
I just got [#<Answer id: 2, question_id: 3, created_at: “2008-01-15
16:11:12”, content:“this is test”, person_id: 12 > but there is no
question_category_name. when I run this in MYSQL I can got:
id: 2, question_id: 3, created_at: “2008-01-15 16:11:12”,
content:“this is test”, person_id: 12, question_category_name:
“Movies / TV”

why did happen?
by the way, When I run this on rails 1.2.6. there is no problem. and
the result is my wanted. like:
id: 2, question_id: 3, created_at: “2008-01-15 16:11:12”,
content:“this is test”, person_id: 12, question_category_name:
“Movies / TV”

who can help me? Thanks!!

I think this can help you

"find_by_sql(sql)

Executes a custom sql query against your database and returns all the
results. The results will be returned as an array with columns
requested encapsulated as attributes of the model you call this method
from. If you call +Product.find_by_sql+ then the results will be
returned in a Product object with the attributes you specified in the
SQL query. "

On Jan 15, 2008 10:21 PM, OnRails [email protected] wrote:

question_category_name
question_category_name. when I run this in MYSQL I can got:

who can help me? Thanks!!


Rafael Mueller