下面的 find 方法返回所有记录,但不包括场所表列。有没有办法可以修改以下内容以包含来自场地的列?我试过了:select => 'venues.id'
,而且:select => 'venues.*'
,无济于事。也许这是 rails find 方法的限制。可以将查询重写为“Item.where”以包含所有列吗?
@vehicles = Vehicle.find(:all,
:select => '*',
:joins => [:vehicle_status, :category, :user],
:include => [:venue],
:conditions => ["vehicles.client_id = ? ", current_user.client_id]
)
我正在使用导轨 3.2.11。
另外,当我:select => 'vehicles.*, venues.*'
在控制台上使用并获取以下查询时,它会显示正在选择的场所字段,但它们不会出现在返回的 json 中:
SELECT "vehicles"."id" AS t0_r0, ... "vehicles"."created_at" AS t0_r33,
"vehicles"."updated_at" AS t0_r34, "venues"."id" AS t1_r0, "venues"."client_id" AS t1_r1,
"venues"."venue_name" AS t1_r2, "venues"."created_at" AS t1_r3, "venues"."updated_at" AS t1_r4
FROM "vehicles" INNER JOIN "vehicle_statuses" ON "vehicle_statuses"."vehicle_status_code" =
"vehicles"."status_code" INNER JOIN "categories" ON "categories"."id" =
"vehicles"."category_id" INNER JOIN "users" ON "users"."id" = "vehicles"."created_at_user_id"
LEFT OUTER JOIN "venues" ON "venues"."id" = "vehicles"."venue_id" WHERE (vehicles.client_id =
500 )
但是,如果我使用:select => '*'
,控制台会显示两个查询:一个用于车辆表,另一个用于场地:Venue Load (0.3ms) SELECT "venues".* FROM "venues" WHERE "venues"."id" IN (5000 )