STI and fixtures

Hi all !

Loading fixtures doens't seems to associate my 2 objects, do know what's wrong ?

In app/

class Manager < Employee

  has_many :employees,     :foreign_key => :reports_to

end

class Employee < Person

  belongs_to :manager,     :foreign_key => 'reports_to'

end

class Person < ActiveRecord::Base   belongs_to :address end

fixtures for people

Nicolas:   first_name: Nicolas   type: Employee   reports_to: david

David:   first_name: David   type: Manager

after loading the fixtures, in the console

e=Employee.find(:first)

=> #<Employee id: 5038945, type: "Employee", title_id: nil, first_name: "Nicolas", reports_to: 0, created_at: "2008-07-20 18:33:49", updated_at: "2008-07-20 18:33:49">

e.reports_to

=> 0

Loading fixtures doens't seems to associate my 2 objects, do know what's wrong ?

fixtures for people

Nicolas: first_name: Nicolas type: Employee reports_to: david

David: first_name: David type: Manager

That should be reports_to: David (it must exactly match the fixture label)

Fred

Frederick Cheung wrote:

type: Manager

That should be reports_to: David (it must exactly match the fixture label)

Fred

problem problem with

Nicolas:   first_name: Nicolas   type: Employee   reports_to: David

Nicolas is still reporting to 0 instead of David id ...

  -- help --

Frederick Cheung wrote:

type: Manager

That should be reports_to: David (it must exactly match the fixture label)

Fred

problem problem with

Nicolas: first_name: Nicolas type: Employee reports_to: David

I'm being slow - you need to use the association name, not the column
name (ie manager: David)

Fred

Frederick Cheung wrote:

nico Itkin wrote:

Frederick Cheung wrote:

Fred

problem problem with

Nicolas: first_name: Nicolas type: Employee reports_to: David

I'm being slow - you need to use the association name, not the column name (ie manager: David)

Fred

thanks works great now !!

a last question of you're still here : how to implement via collections has_and_belongs_to_many ?

Frederick Cheung wrote:

Nicolas: first_name: Nicolas type: Employee reports_to: David

I'm being slow - you need to use the association name, not the column name (ie manager: David)

Does this mean the fixture system now reads and navigates the Models' has_many etc associations? That's new - and incredibly needed!

(Our 1.2.x fixtures at work have grown so dense that adding new ones, to set new scenarios up, is a positive drain on our velocity!)

nico Itkin wrote:

Frederick Cheung wrote:

Fred

problem problem with

Nicolas: first_name: Nicolas type: Employee reports_to: David

I'm being slow - you need to use the association name, not the
column name (ie manager: David)

Fred

thanks works great now !!

a last question of you're still here : how to implement via
collections has_and_belongs_to_many ?

This is in the docs: Peak Obsession
but in a nutshell: - you don't need to specify the join table at all - just comma separate the labels of the appropriate records eg if an
employee had and belongs to many projects you might have

Nicholas:    projects: death_star, relaunch, nemesis

to say that that user is a member of those projects.

Fred

Frederick Cheung wrote:

Nicolas: first_name: Nicolas type: Employee reports_to: David

I'm being slow - you need to use the association name, not the column name (ie manager: David)

Does this mean the fixture system now reads and navigates the
Models' has_many etc associations? That's new - and incredibly needed!

It was new in 2.0. Peak Obsession
has some examples and googling for 'foxy fixtures' should turn up some
more.

Fred

   Phlip

yes

This is in the docs: Peak Obsession but in a nutshell: - you don't need to specify the join table at all - just comma separate the labels of the appropriate records eg if an employee had and belongs to many projects you might have

Nicholas:    projects: death_star, relaunch, nemesis

to say that that user is a member of those projects.

Fred

thanks a lot Fred.