This project is archived and is in readonly mode.

#6488 new
Wylliam Miguita

Rails 3.0.5 load test fixtures doesn't undestand has_many associations

Reported by Wylliam Miguita | February 28th, 2011 @ 07:15 PM

After smelly fix of ticket #6479 (https://rails.lighthouseapp.com/projects/8994/tickets/6479-model-as...) through inflections, the following error occurs while running tests:

ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'categoria' in 'field list': INSERT INTO `hierarquias` (`categoria`, `subcategoria`) VALUES ('jazz', 'big_bands')

where:

class Categoria << ActiveRecord::Base
  has_many :hierarquias
  has_many :subcategorias, :through => :hierarquias, :class_name => "Subcategoria", :foreign_key => :categoria_id
end

class Hierarquia << ActiveRecord::Base
  belongs_to :categoria
end

class Subcategoria < Categoria
  has_one :hierarquia
  has_one :categoria, :through => :hierarquia
end

Comments and changes to this ticket

  • Wylliam Miguita

    Wylliam Miguita February 28th, 2011 @ 07:32 PM

    forgot the fixtures:
    categorias.yml

    musica_brasileira:
        nome: música brasileira
        type: Categoria
    jazz:
        nome: jazz
        type: Categoria
    rock:
        nome: rock
        type: Categoria
    choro:
        nome: choro
        type: Subcategoria
    samba:
        nome: samba
        type: Subcategoria
    big_bands:
        nome: big banda
        type: Subcategoria
    jazz_classico:
        nome: jazz classico
        type: Subcategoria
    
    

    hierarquias.yml

    mb_choro:
        categoria: musica_brasileira
        subcategoria: choro
    mb_samba:
        categoria: musica_brasileira
        subcategoria: samba
    jazz_big:
        categoria: jazz
        subcategoria: big_bands
    jazz_jazz_classico:
        categoria: jazz
        subcategoria: jazz_classico
    
  • Wylliam Miguita

    Wylliam Miguita April 7th, 2011 @ 05:04 PM

    You can call off this ticket.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages