pull data from a third table in a simple relation

1

Hi! I have 3 tables. animal studies, species and provenances, where:

estudoanimais belongs_to especie
estudoanimais has_many_procedencias
especie has_many estudoanimais
procedencia belongs_to estudoanimal

At the moment I create a provenance, I can associate this to a species, drawn from a select as follows:

f.select :estudoanimais_id, Estudoanimal.all.collect{|ea| [ea.especie.nome,ea.id]}

What I would like is to show the name of this chosen species instead of its id on the originals screens. In the console, I'm trying to do it like this:

p=Procedencia.first
nome = p.estudoanimal.especie.nome

and he says he can not bring that name because it's a null value, but if I put it:

p.estudoanimais_id

It brings the value of the id of the species that I chose when creating a provenance. Where am I going wrong?

    
asked by anonymous 06.05.2016 / 15:58

1 answer

0

It's a little tricky, but are not you bringing the ID by NAME?

f.select :estudoanimais_id, Estudoanimal.all.collect{|ea| [ea.id, ea.especie.nome]}
    
10.08.2016 / 03:26