dB'*_*dB' 1 ruby sql postgresql activerecord ruby-on-rails-3
我正试图从表中拔出一列.该命令似乎失败了,因为我的列名是在camel case(practiceType)中.这是我的错误,模型和架构:
> Task.pluck 'practiceType'
(0.5ms) SELECT practiceType FROM "tasks"
PG::Error: ERROR: column "practicetype" does not exist
LINE 1: SELECT practiceType FROM "tasks"
^
: SELECT practiceType FROM "tasks"
ActiveRecord::StatementInvalid: PG::Error: ERROR: column "practicetype" does not exist
Run Code Online (Sandbox Code Playgroud)
task.rb
class Task < ActiveRecord::Base
attr_accessible :name, :practiceType
[...]
Run Code Online (Sandbox Code Playgroud)
schema.db
create_table "tasks", :force => true do |t|
t.string "name"
t.string "practiceType"
[...]
Run Code Online (Sandbox Code Playgroud)
正确的解决方案可能是将列名转换为蛇形,但我更愿意避免这种情况,因为我担心会破坏我的应用程序.是否有一个快速而肮脏的解决方案可以让我的查询运行?
| 归档时间: |
|
| 查看次数: |
338 次 |
| 最近记录: |