This project is archived and is in readonly mode.
has_many + foreign_key in ActiveRecord class not working
-
Adrien Pestel
Mysql version 5.0.51a
-
CancelProfileIsBroken
- Tag changed from 2.3.3, :foreign_key to 2.3.3, :foreign_key, bugmash
-
David Trasbo
I was unable to reproduce this bug in 2.3.3:
The two models:
@@@ Ruby class Entity < ActiveRecord::Base
set_table_name 'glpi_entities' has_many :trackings, :class_name => 'Tracking', :foreign_key => 'FK_entities' endclass Tracking < ActiveRecord::Base
set_table_name 'glpi_tracking' belongs_to :entity, :foreign_key => 'FK_entities' end
Loading development environment (Rails 2.3.3)Console output:
entity = Entity.create => # 3.times { entity.trackings.create } => 3 entity.trackings => [#, #, #]
This ticket may be marked as invalid. -
David Trasbo
Formatting fail.
Models:
class Entity < ActiveRecord::Base set_table_name 'glpi_entities' has_many :trackings, :class_name => 'Tracking', :foreign_key => 'FK_entities' end class Tracking < ActiveRecord::Base set_table_name 'glpi_tracking' belongs_to :entity, :foreign_key => 'FK_entities' endConsole output:
Loading development environment (Rails 2.3.3) >> entity = Entity.create => #<Entity id: 1, created_at: "2009-08-08 14:49:11", updated_at: "2009-08-08 14:49:11"> >> 3.times { entity.trackings.create } => 3 >> entity.trackings => [#<Tracking id: 1, FK_entities: 1, created_at: "2009-08-08 14:49:25", updated_at: "2009-08-08 14:49:25">, #<Tracking id: 2, FK_entities: 1, created_at: "2009-08-08 14:49:25", updated_at: "2009-08-08 14:49:25">, #<Tracking id: 3, FK_entities: 1, created_at: "2009-08-08 14:49:25", updated_at: "2009-08-08 14:49:25">] -
Adrien Pestel
The id field was setted up as uppercase in the original database...
I've added set_primary_key :ID in each models.
It works now.The ticket can be closed sorry for disturbing.
Regards,
Adrien -
José Valim
- State changed from new to invalid
- Tag changed from 2.3.3, :foreign_key, bugmash to 2.3.3, :foreign_key