Reputation: 4634
I've been confused for a while, I follow the rails doc, and it say
Client.select("viewable_by, locked")
will only select only a subset of fields.
Now I got a model call Goods
class Goods < ActiveRecord::Base {
:id => :integer,
:name => :string,
:translate_key => :string,
:created_at => :datetime,
:updated_at => :datetime,
:discount_json => :text,
:price_mapping => :text,
:goods_type => :string,
:reference_id => :integer,
:available => :boolean
}
When I try Goods.select(:name)
, it works fine.
However, when I did
Goods.select(:name,:translate_key)
It threw ArgumentError: wrong number of arguments (2 for 0..1)
Upvotes: 0
Views: 239
Reputation: 23711
If you want to pass multiple columns pass them in an array
Goods.select([:name, :translate_key])
This way you can still use symbols
Active record select
Upvotes: 1
Reputation: 1118
Try this:
Goods.select("name,translate_key")
Reference: Active Recor Query Interface
Upvotes: 1