【发布时间】:2020-06-04 05:53:15
【问题描述】:
我有以下颤振沼泽查询
(select(recipeGarnishes)..where((tbl) => tbl.postGarnish.equals(true))).get();
如何将distinct 条件添加到查询中?
更新: 我要写的查询是:
select DISTINCT garnishName from RecipeGarnishes where postGarnish = 'true'
garnishName 和 postGarnish 是我的 RecipeGarnishes 表中的列
更新 2:
根据答案,我尝试了这个。
final query = selectOnly(recipeGarnishes, distinct: true)
..addColumns([recipeGarnishes.garnishName])
..where(recipeGarnishes.postGarnish.equals(postGarnish));
List<TypedResult> result = await query.get();
return result.map((row) => row.readTable(recipeGarnishes)).toList();
但它给了我以下错误
Moor:发送 SELECT DISTINCT recipe_garnishes.garnish_name AS "recipe_garnishes.garnish_name" FROM recipe_garnishes WHERE recipe_garnishes.post_garnish = ?;带参数 [1]
[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] 未处理的异常:NoSuchMethodError:getter 'garnishName' 被调用为 null。
【问题讨论】:
-
如果不支持
distinct,您可以随时使用groupBy -
它似乎支持它,我只是找不到任何文档。
-
但是我该如何使用呢?
标签: flutter flutter-moor