使用#select 代替#pluck 并调用.as_json 或.map(&:attributes)
Store.joins(:paid => :supply).group(:name)
.select("supply.name").where("stores.identifier IN (?) ", tids)
.select(:supply_id, :name).as_json
# [{supply_id: 258, name: "Square"}, {supply_id: 245, name: "App"}]
或
Store.joins(:paid => :supply).group(:name)
.select("supply.name").where("stores.identifier IN (?) ", tids)
.select(:supply_id, :name).map(&:attributes)
# [{supply_id: 258, name: "Square"}, {supply_id: 245, name: "App"}]
或者你可以构造带有{import_id: 1, cost: 0}的哈希
Store.joins(:paid => :supply).group(:name)
.select("supply.name").where("stores.identifier IN (?) ", tids)
.select(:supply_id, :name)
.map {|e| {supply_id: e.supply_id, name: e.name, import_id: 1, cost: 0} }
# [{supply_id: 258, name: "Square", import_id: 1, cost: 0}, {supply_id: 245, name: "App", import_id: 1, cost: 0}]
或
您可以在哈希生成步骤中使用Hash#merge 来包含{import_id: 1, cost: 0}
hash.merge({import_id: 1, cost: 0})
# To achieve: {{supply_id: 258, name: "Square", import_id: 1, cost: 0}, {supply_id: 245, name: "App", import_id: 1, cost: 0}}