Amigos, tenho as seguintes saidas do console (Rails 4.1):
Product.all
Product Load (0.2ms) SELECT "products".* FROM "products"
=> #<ActiveRecord::Relation [#<Product id: 4, cod: "160", descricao: "Sutiã", price: #<BigDecimal:103c2d810,'0.1E2',9(27)>, created_at: "2016-05-18 17:05:35", updated_at: "2016-05-18 17:05:35">]>
Size.all
Size Load (0.8ms) SELECT "sizes".* FROM "sizes"
=> #<ActiveRecord::Relation [#<Size id: 1, descricao: "P", created_at: "2016-03-09 23:23:49", updated_at: "2016-03-09 23:23:49">, #<Size id: 2, descricao: "M", created_at: "2016-03-09 23:23:56", updated_at: "2016-03-09 23:23:56">, #<Size id: 3, descricao: "G", created_at: "2016-03-09 23:24:00", updated_at: "2016-03-09 23:24:00">]>
Variation.all
Variation Load (0.2ms) SELECT "variations".* FROM "variations"
=> #<ActiveRecord::Relation [#<Variation id: 35, product_id: "4", size_id: "1", color_id: "1", quantity: 4, barcode: "160P1000001000", created_at: "2016-05-18 17:05:35", updated_at: "2016-06-01 18:45:19">, #<Variation id: 36, product_id: "4", size_id: "2", color_id: "2", quantity: 10, barcode: "160M1100001000", created_at: "2016-05-18 17:05:35", updated_at: "2016-06-01 17:15:24">]>
E quando executo este comando:
Variation.joins(:product,:size,:color).select('products.cod as cod_produto,products.descricao as desc_produto,colors.descricao as desc_cor,sizes.descricao as desc_tamanho,products.price as preco,variations.quantity as quantidade,variations.barcode as cod_barras')
Recebo esta resposta:
#<ActiveRecord::Relation [#<Variation id: nil>, #<Variation id: nil>]>
O que está errado ? Se eu executar a query direto ele retorna mas eu preciso que seja feito com o active record pois preciso gerar um csv disso.