postgresql - Rails Article.find 1 raises ActiveRecord::StatementInvalid on legacy database -
i'm creating rails app on legacy database table. works fine locally, on server hit error whenever article.find(1)
could not log "sql.active_record" event. nomethoderror: undefined method `name' nil:nilclass activerecord::statementinvalid: pg::error: error: zero-length delimited identifier @ or near """" line 1: select "articles".* "articles" "articles"."" = $1 limit 1
the legacy database has id field, schema describes id with
create_table "articles", :id => false, :force => true |t| t.decimal "id", :precision => 10, :scale => 0, :null => false ...
note article.find_by_id(1) returns record without problem.
any ideas how fix this?
updated - see below
it turns out, adding following model fixes this:
class article < activerecord::base set_primary_key :id ...
presumably, because rails didn't create table, doesn't know field primary key is. seems little odd though, educated guess warning - or more friendly error message - appreciated.
update: rails 3.2+ above method deprecated. new method follows:
class article < activerecord::base self.primary_key = :id ...
thanks @lboix pointing out!
Comments
Post a Comment