有没有办法通过ActiveRecord获得实际的列名称?
当我调用find_by_sql或select_all with a join时,如果有同名的列,则会覆盖第一列:
select locations.*, s3_images.* from locations left join s3_images on s3_images.imageable_id = locations.id and s3_images.imageable_type = 'Location' limit 1
在上面的例子中,我得到了以下结果:
#<Location id: 22, name: ...
>
其中id是最后一张s3_图像的id.select_rows( Select 行)是唯一按预期工作的功能:
Model.connection.select_rows("SELECT id,name FROM users") => [["1","amy"],["2","bob"],["3","cam"]]
我需要获取上面行的字段名.
ActiveRecord连接方法创建多个对象.我正在try 实现与"includes"返回相同的结果,但使用左连接.
我试图返回大量结果(有时是整张表),这就是为什么Include不适合我的需要.