How do you order fixtures within each yml file?



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?