Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11599 (new defect)

Opened 1 month ago

Fixtures with STI will partially fail

Reported by: plafoucriere Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 2.0.1
Severity: major Keywords: fixtures, sti
Cc:

Description

Hi,

I try to use fixtures to populate my db (I can't find any best practice on rails + populating db values). In my particular case, I have a model called App, and another called Category. Both has children classes using STI (resp. PcApp, MobileApp and PcCategory, MobileCategory).

Here's some example fixtures for apps.yml :

google_mobile:
    name: Google
    icon: google.png
    pc_categories: search_mobile,wap_mobile
    url: http://www.google.fr
    type: MobileApp    

google_pc:
    name: Google
    icon: google.png
    pc_categories: search_pc
    url: http://www.google.fr
    type: PcApp    

and for categories.yml :

search_mobile:
    name: Search
    type: MobileCategory
        
wap_mobile:
    name: Wap
    type: MobileCategory

search_pc:
    name: Search
    type: PcCategory

in each subclass (PcApp or MobileApp), I have a habtm relationship to respective category. When using these relations inside the console, everything goes fine, and db is populated corrected.

But, When using the rake db:fixtures:load, I will get in apps_categories only the very last category used.

I mean, if the last entry type in apps.yml a is PcApp with PcCategories, I will have only PcCategories in apps_categories.

Since it's working by hand, and the problem only occurs with rake db:fixtures:load, I think there's a bug there.