# Fixtures loading \*very\* strangely

**URL:** <https://www.ruby-forum.com/t/fixtures-loading-very-strangely/159903>\
**Category:** Rails\
**Created:** [February 9, 2009, 10:47pm UTC](https://www.ruby-forum.com/t/fixtures-loading-very-strangely/159903 "2009-02-09T22:47:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/977dab/32.png) [@bcm](https://www.ruby-forum.com/u/bcm)\
**Post date:** [February 9, 2009, 10:47pm UTC](https://www.ruby-forum.com/t/fixtures-loading-very-strangely/159903/1 "2009-02-09T22:47:03Z")

</div>

Hi all,

I’ve just hit a snag, and I’m hoping somebody out there can help.

I’m working on an app that uses some legacy tables. One of them doesn’t  
have a column named “id” so I’ve got the following:

class Student  
set\_primary\_key ‘pidm’  
alias\_attribute :id, :pidm  
end

When I’m testing, I need 5 student fixtures. I have them defined like  
this one:

john\_doe:  
status: student  
department:  
alumni:  
title:  
applicant:  
student\_status:  
staff:  
pref\_first\_name:  
faculty:  
applicant\_status:  
year\_in\_school: freshman  
chair:  
pidm: 12345678  
reed\_id: L12345  
program:  
middle\_initial:  
first\_name: John  
student: Y  
login: doej  
last\_name: Doe  
email: removed\_email\_address@domain.invalid

When I load the fixtures into my test database with “rake  
db:fixtures:load RAILS\_ENV=test” everything works great. However, when  
I run my test suite, and rails loads the fixtures, I get a big problem:  
three of the fixtures aren’t loading with their pidm (id) correctly.  
All three load with a pidm of 91, which is problematic since it breaks  
any associations involving that primary key.

The two other fixtures load ok, though, which makes me very confused.

I’ve played around with the data differences between the fixtures, and  
futzing the non-pidm data doesn’t seem to do anything.

Has anybody encountered this? Any advice?

Thanks!

---

<div class="post-metadata">

**Author:** ![bcm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/977dab/32.png) [@bcm](https://www.ruby-forum.com/u/bcm)\
**Post date:** [February 9, 2009, 11:44pm UTC](https://www.ruby-forum.com/t/fixtures-loading-very-strangely/159903/2 "2009-02-09T23:44:02Z")

</div>

On Feb 9, 2009, at 4:47 PM, Brent M. wrote:

> set\_primary\_key ‘pidm’  
> alias\_attribute :id, :pidm  
> end

I’m not sure if it changes your situation, but you shouldn’t need that  
alias\_attribute. Just use id and ActiveRecord should use your real  
primary key column under the covers.

-Rob

---

<div class="post-metadata">

**Author:** ![bcm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/977dab/32.png) [@bcm](https://www.ruby-forum.com/u/bcm)\
**Post date:** [February 9, 2009, 11:54pm UTC](https://www.ruby-forum.com/t/fixtures-loading-very-strangely/159903/3 "2009-02-09T23:54:57Z")

</div>

I’ve tried that; there are lots of things out there that assume the  
primary key is called “id” – this simple fix makes all of them work.

Even if I remove it, though, I still get the same weird loading  
behavior. ☹

Rob B. wrote:

> On Feb 9, 2009, at 4:47 PM, Brent M. wrote:
> 
> > set\_primary\_key ‘pidm’  
> > alias\_attribute :id, :pidm  
> > end
> 
> I’m not sure if it changes your situation, but you shouldn’t need that  
> alias\_attribute. Just use id and ActiveRecord should use your real  
> primary key column under the covers.
> 
> -Rob
