come posso ottenere le associazioni has_many di un modello?ROTAIE: Come ottenere associazioni has_many di un modello
Per esempio se ho questa classe:
class A < ActiveRecord::Base
has_many B
has_many C
end
se fosse un metodo come questo:
A.get_has_many
che restituiscono
[B,C]
E 'possibile? Grazie!
Per ottenere solo 'associazioni has_many', è è possibile passare un parametro: 'A.reflect_on_all_associations (: has_many) .map (&: nome) # => [: B, C]' – Voyta
c'è un modo per riflettere (ad esempio traverse) su un'istanza * * variabile , dove le associazioni sono stati caricati con entusiasmo? –
Mark Richman: self.class.reflect_on_all_associations ... – stebooks