My Cardset table looks like:
create_table "cardsets", force: :cascade do |t|
t.string "name", null: false
t.string "code", null: false
t.integer "setOrder", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["code"], name: "index_cardsets_on_code", unique: true
end
When I run the command:
Cardset.all.order('setOrder ASC')
it responds with:
Traceback (most recent call last):
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column
"setorder" does not exist) LINE 1: SELECT "cardsets".* FROM "cardsets" ORDER
BY setOrder ASC L...
HINT: Perhaps you meant to reference the column "cardsets.setOrder".
: SELECT "cardsets".* FROM "cardsets" ORDER BY setOrder ASC LIMIT $1
Running the query again, sorting by any other field works normally as it should.
I have a Card table which looks exactly the same as the Cardset table, with a cardOrder field and the same problem arises when running a Order query on that table too.
The only way I can get this to work is by encapsulating the column name with "columnName"
qoutation marks like so:
Cardset.all.where('"setOrder" ASC')
Can anyone explain what is going on behind the scenes here.