Question

I am stuck at join two tables using active record 3.0

Table A
id name
1 xcv

Table B #a_id is foreign_key
id date a_id
1 9/15 1

How to query using active record to get output as
id date a_name
1 9/15/ xcv

When I do

B.joins(:A)

in Model B than I get following sql

SELECT "B".* FROM "B" INNER JOIN "A" ON "A"."ID" = "B"."A_ID"

When I query it on our DB it give correct output but rails logger has wrong output

#<B id: 1, date"9/15/11", a_id: 2>

I want is

#<B id: 1, date"9/15/11", a_name: xcv>

Relation is as follow

A has_many :B
B belongs_to :A

Any help is really appreciated..

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top