开发者

How can I name a sqlite column "primary" with Rails?

开发者 https://www.devze.com 2023-02-01 16:41 出处:网络
I\'m trying to create this table in Rails: create_table :artist_names do |t| t.string :name t.boolean :primary, :default => true

I'm trying to create this table in Rails:

create_table :artist_names do |t|
  t.string :name
  t.boolean :primary, :default => true
  t.integer :artist_id

  t.datetime :deleted_at
  t.timestamps
end

However, my queries against it fail:

[Dev]> ArtistName.all(:conditions => ['artist_names.primary = ?', true])  ArtistName Load (0.0ms)
SQLite3::SQLException: near "primary": syntax error: SELECT * FROM "artist_names" WHERE (artist_names.primary = 't') AND ("artist_names"."deleted_at" IS NULL)
ActiveRecord::StatementInvalid: SQLite3::SQLException: near "primary": syntax error: SELECT * FROM "artist_names" WHERE (artist_names.primary = 't') AND ("artist_names"."deleted_at" IS NULL) 

My queries work when I change the column's name to something else, but the name "primary" 开发者_如何学运维makes the most sense to me.

How can I make this work while keeping the column name "primary"?


User back-ticks around primary word.

ArtistName.all(:conditions => ['`primary` = ?', true]) ...
0

精彩评论

暂无评论...
验证码 换一张
取 消