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: doej-FruA4mHk9Qo@public.gmane.org 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 9, 2009, at 4:47 PM, Brent Miller wrote:> > 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 > endI''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> > > 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: doej-FruA4mHk9Qo@public.gmane.org > > 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! > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Biedenharn wrote:> On Feb 9, 2009, at 4:47 PM, Brent Miller 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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---