# Help with loading data with sequential id

**URL:** <https://www.ruby-forum.com/t/help-with-loading-data-with-sequential-id/172035>\
**Category:** Rails\
**Created:** [July 13, 2009, 5:35pm UTC](https://www.ruby-forum.com/t/help-with-loading-data-with-sequential-id/172035 "2009-07-13T17:35:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 13, 2009, 5:35pm UTC](https://www.ruby-forum.com/t/help-with-loading-data-with-sequential-id/172035/1 "2009-07-13T17:35:30Z")

</div>

Hello,

I’m trying to load data into my mysql table using the following:

============ load\_codes\_data.rb ============  
require ‘active\_record/fixtures’  
class LoadCodesData \< ActiveRecord::Migration  
def self.up  
down  
directory = File.join(File.dirname(“MY\_DIR\_NAME”), “data”)  
Fixtures.create\_fixtures(directory, “codes”)  
end

# def self.down Code.delete\_all end end

and here’s the yaml file:

# =============== codes.yml =================== I: seq: 1 cat: source description: Member II: seq: 2 cat: source description: Friends or Family III: seq: 3 cat: source description: Book IV: seq: 4 cat: source description: Search Engine V: seq: 5 cat: source description: Magazine VI: seq: 6 cat: source description: Other … …

Here’s my question.  
Codes table has the three fields you see in the yaml file and a unique  
id field that gets populated automatically and gets assigned a random  
non-sequential numbers. I would like for it to get sequential ids  
assigned. I’ve searched for a while, but haven’t come across a  
solution… Can anyone help?

Thanks,  
Kumi

---

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 13, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/help-with-loading-data-with-sequential-id/172035/2 "2009-07-13T18:21:41Z")

</div>

I suppose you want use the omap YAML type. Read about it in  
[http://api.rubyonrails.org/classes/Fixtures.html](http://api.rubyonrails.org/classes/Fixtures.html) and in  
[Ordered Mapping Language-Independent Type for YAML™&nbsp;Version&nbsp;1.1](http://yaml.org/type/omap.html).

Regards.

Franco C…

---

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 13, 2009, 8:58pm UTC](https://www.ruby-forum.com/t/help-with-loading-data-with-sequential-id/172035/3 "2009-07-13T20:58:53Z")

</div>

Thanks for the pointer! I modified the codes.yml file to look like  
this (below) and now it inserts ordered list with sequential ids. I  
had to try it several times to get the spacing right… I had two  
spaces (no tabs) in front of the key:value pair initially, but it  
needed four spaces instead.

=============== codes.yml ===================  
— !omap

- r1:  
id: 1  
seq: 1  
cat: source  
description: Member
- r2:  
id: 2  
seq: 2  
cat: source  
description: Friends or Family
- r3:  
id: 3  
seq: 3  
cat: source  
description: Book
- r4:  
id: 4  
seq: 4  
cat: source  
description: Search Engine
- r5:  
id: 5  
seq: 5  
cat: source  
description: Magazine
- r6:  
id: 6  
seq: 6  
cat: source  
description: Other

=========================================
