Rails 4 - has_many through fetching issue -


i have many many association wich being implemented rails has_many through shortcut.

my models called:

  1. cliente
  2. statustransacaopagseguro
  3. historico

they defined way:

class statustransacaopagseguro < activerecord::base   has_many :historicos   has_many :clientes, through: :historicos end  class cliente < activerecord::base   has_many :historicos   has_many :status_transacao_pag_seguros, through: :historicos end  class historico < activerecord::base   belongs_to :cliente   belongs_to :status_transacao_pag_seguro end 

i have following historico record:

#<historico id: 1, cliente_id: 3, status_transacao_pag_seguros_id: 3, created_at: "2014-06-01 19:44:42", updated_at: "2014-06-01 19:44:42"> 

when run

historico.cliente 

i associated 'cliente' record, when run

historico.status_transacao_pag_seguro 

i nil.

where's problem? defined pluralization correctly? since names in portuguese language think there's problem don't know how overcome that.

your fk status_transacao_pag_seguro in historicos table wrong. should status_transacao_pag_seguro_id (without s). following migration should go:

def change   rename_column :historicos, :status_transacao_pag_seguros_id, :status_transacao_pag_seguro_id end 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -