We have 30-40 tables in a legacy db with no PKs. These tables hold various logging events and may be searched by a given day, a given user id, a given event, etc., but not by a particular row id. So there are reasonable reasons to not have PKs on all tables. Unfortunately, AR really like PKs... If I set_primary_key nil I can't do a create (I get an interning empty string error). If I set the PK to an arbitrary integer column then that column is set to NULL (on an insert), despite its value being passed in the attributes hash... I don't yet have a solution.
Jeff On Sep 16, 6:48 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote: > Howard Yeh wrote: > > Hi All, > > > When saving a record to a table that doesn't use primary key, the > > adapater raises > > > ActiveRecord::StatementInvalid: PGError: ERROR: column "id" does not > > exist > > [....] > > > The problem is that ActiveRecord::Base.create > > would pass in the primary_key "id" for the > > parameter pk even though the ActiveRecord class > > doesn't have a primary key. > > When would you ever want to use an AR model without a primary key? The > only case I can think of where Rails doesn't want a primary key is on > habtm join tables, which don't have an associated model class. > > [...] > > > > > Or is there a way to set the primary key to nil? > > > class Foo < ActiveRecord::Base > > set_primary_key nil > > primary_key # => "" > > end > > Seems like a really bad idea. Without a primary key, there is no way to > uniquely identify a record. Why do you want to do this? > > > > > Howard > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > [email protected] > -- > Posted viahttp://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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

