# AR load script only loading every other item?

**URL:** <https://www.ruby-forum.com/t/ar-load-script-only-loading-every-other-item/98970>\
**Category:** Rails\
**Created:** [January 30, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/ar-load-script-only-loading-every-other-item/98970 "2006-01-30T19:53:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [January 30, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/ar-load-script-only-loading-every-other-item/98970/1 "2006-01-30T19:53:59Z")

</div>

Wow, this one is weird. I’ve got a file with data I want to import,  
one item per line. When I run this code, only the first, third,  
fifth, etc items get saved:

require ‘…/app/models/entitlement’

#### Add entitlements

f = File.open("…/tmp/entitlements.csv")  
f.each do |line|  
id, code, description = line.chomp.split(’|’)  
entitlement = Entitlement.new  
entitlement.code = code  
entitlement.description = description  
entitlement.save  
end  
f.close

Where am I going wrong? It’s just not saving the second, fourth, etc  
items.

If I test the saving, that confirms that it’s not saving, but I don’t  
know why:

…  
if entitlement.save  
p “Saved #{code}”  
end  
…

“Saved wireless”  
“Saved vpn”  
“Saved trac”  
“Saved svn”

The file:

1|wireless|Wireless Network  
2|wirelessStudent|Student Wireless Network  
3|vpn|VPN  
4|email|Email Account  
5|trac|Trac  
6|calendar|Calendar Account  
7|svn|Source Code Repository  
8|directory|Directory Listing

Any ideas? I know I’ve run this import before and it’s worked.

Thanks!

Sean

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [January 30, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/ar-load-script-only-loading-every-other-item/98970/2 "2006-01-30T21:46:51Z")

</div>

Answered it myself (I think). In the model, don’t put:

validates\_uniqueness\_of :id

I have no idea why that one just hit me now, but at least, after  
removing that, everything works.

Sean
