I have this query:
@tudo = Isolated.joins("LEFT JOIN resists ON resists.isolated_id = isolateds.id").joins("LEFT JOIN genes ON genes.isolated_id = isolateds.id LEFT JOIN stats ON stats.gene_id = genes.id LEFT JOIN mutations ON mutations.id = stats.mutation_id").all
I want to fetch fields from the Gene
model, such as the name
field.
When I do the @ everything in the rails console (rails c), this appears to me:
Isolated Load (4.4ms) SELECT 'isolateds'.* FROM 'isolateds' LEFT JOIN resists ON resists.isolated_id = isolateds.id LEFT JOIN genes ON genes.isolated_id = isolateds.id LEFT JOIN stats ON stats.gene_id = genes.id LEFT JOIN mutations ON mutations.id = stats.mutation_id
=> #<ActiveRecord::Relation [#<Isolated id: 1, name: "xpto", disease: "sklhafl", n_samples: 1, origin_id: 1, organism_id: 3, created_at: "2015-03-23 16:21:20", updated_at: "2015-03-23 16:21:20">, #<Isolated id: 2, name: "khjlsdkf", disease: "lkajsçdl", n_samples: 123, origin_id: 1, organism_id: 1, created_at: "2015-03-26 18:57:02", updated_at: "2015-03-26 18:57:02">,...
That is, only Isolated data, even the tables being put together.
if you do @tudo.select("genes.name")
, in the rails console give me this:
#<ActiveRecord::Relation [#<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, #<Isolated id: nil, name: nil>, ...]>
and when in the html.erb file I do:
@tudo.gene.name
gives me error, how can I go get the gene name?