Zack Chandler
2006-Feb-21 16:09 UTC
[Rails] How do you order fixtures within each yml file?
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060221/6556344a/attachment.html