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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zack C. (Guest)
on 2006-02-21 18:09
(Received via mailing list)
Hi.

I've come across the following documentation:

Note that YAML fixtures are unordered. If you want ordered fixtures, use
the
omap YAML type. See yaml.org/type/omap.html for the specification. You
will
need ordered fixtures when you have foreign key constraints on keys in
the
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 %>@gmail.com
<% 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
mismatch.

Any ideas?

Thanks,
Zack
This topic is locked and can not be replied to.