Post.find(:all, :select => "DISTINCT author")
return
[#<Post author: nil>, #<Post author: nil>, #<Post author: nil>, #<Post author: nil>, #<Post author: nil>]
。select distinct returns nil(globalize3)
但SQL請求SELECT DISTINCT author FROM posts;
按預期工作。
我正在使用globalize3。 Post.select('DISTINCT author').with_translations('en')
返回所有記錄。
下面是它的日誌中:
Post Load (0.5ms) SELECT "posts"."id" AS t0_r0, "posts"."description" AS t0_r1, "posts"."position" AS t0_r2, "posts"."created_at" AS t0_r3, "posts"."updated_at" AS t0_r4, "posts"."date"
AS t0_r5, "post_translations"."id" AS t1_r0, "post_translations"."post_id" AS t1_r1, "post_translations"."locale" AS t1_r2, "post_translations"."author"
AS t1_r3, "post_translations"."description" AS t1_r4, "post_translations"."created_at" AS t1_r5, "post_translations"."updated_at"
AS t1_r6 FROM "posts" LEFT OUTER JOIN "post_translations" ON "post_translations"."post_id" = "posts"."id" WHERE "post_translations"."locale" = 'en'
AND (post_translations.author IS NOT NULL)
我怎麼可以只選擇不同的值?
請發表日誌塊用兩個請求 – Bohdan
已更新。這是第一個請求:'ActionView :: Template :: Error(No route matches {:action =>「show」,:controller =>「posts」,:id =>#}):' –
NARKOZ