Forum: Ruby on Rails How do you order fixtures within each yml file?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C4dc94c893471878a105761a9207f29b?d=identicon&s=25 Zack Chandler (Guest)
on 2006-02-21 17:09
(Received via mailing list)

I've come across the following documentation:

Note that YAML fixtures are unordered. If you want ordered fixtures, use
omap YAML type. See for the specification. You
need ordered fixtures when you have foreign key constraints on keys in
same table. This is commonly needed for tree structures. Example:

   --- !omap
   - parent:
       id:         1
       parent_id:  NULL
       title:      Parent
   - child:
       id:         2
       parent_id:  1
       title:      Child

I'm unable to make sense of how to actually do this in order to make
my dynamic fixtures
load in the order specified in the file.
I'm doing something like this for loading practice data:

--- users.yml ---
<% screen_names = [ 'foo', 'bar', 'foobar' ] %>
<% screen_names.each do |name| %>
<%= name %>:
  username: <%= name %>
  hashed_password: 12345
  salt: 12345
  screen_name: <%= name %>
  email_address: <%= name %>
<% end %>

The data is loaded fine but foo is not loaded first as you would
expect.  I'm trying
to link up records in other fixtures to foos record using user_id and
of course the keys

Any ideas?

This topic is locked and can not be replied to.