出于兴趣,我试图重写
Model.joins{other_model}.uniq
(生成):
=> "SELECT DISTINCT [model].* FROM [model] INNER JOIN [other_model] ON [other_model].[model_id] = [model].[id]"
在纯粹的Squeel中,然而我能得到的最接近的是
Model.joins{other_model}.select{distinct(id)}
生成:
=> "SELECT DISTINCT [model].[id] FROM [model] INNER JOIN [other_model] ON [other_model].[model_id] = [model].[id]"
我如何在Squeel中做DISTINCT [model].*
?有可能吗?
由于
答案 0 :(得分:2)
你需要在反引号中引用*
Model.select{distinct(`*`)}.to_sql
产地:
SELECT distinct(*) from `models`
答案 1 :(得分:0)
你不能传递通配符吗?
Model.joins{other_model}.select{distinct('*')}