我正在使用带有select的rails执行连接查询,但结果对于已连接的表具有null id ...
@result = Table.joins(:join_table).select(['join_table.id', 'name', 'random_attr', 'created_at']).where('table.random_attr = ?', @anotherresult.id).order('name ASC')
结果......
[
{
random_attr: true
created_at: "2012-10-31T02:23:07Z"
id: null
name: "Joe"
},
....
]
生成的sql看起来像......
SELECT join_table.id, name, random_attr, created_at FROM `table` INNER JOIN `join_table` ON `join_table`.`id` = `table`.`user_id` WHERE (random_attr = 9) ORDER BY name ASC;
直接在mysql中执行此查询工作正常。