在葡萄实体中,我想只显示一个字段(不是零?)而没有运气。
我正在尝试使用此代码,但根本无法正常工作,但始终隐藏该字段。
expose :winner, :using => PlayerEntity, :unless => { :winner => nil }
我认为代码本身解释了我真正需要的东西,但正如我所说,我没有得到预期的结果。
有任何线索吗?
答案 0 :(得分:10)
好的,检查葡萄实体的代码我发现你需要将这个块作为Ruby Proc传递。 此代码将按预期工作:
expose :winner, :using => PlayerEntity, :unless => Proc.new {|g| g.winner.nil?}
希望它有所帮助。 干杯
答案 1 :(得分:0)
https://github.com/ruby-grape/grape-entity#expose-nil
Grape Entity现在提供了with clean as (
select
trans_date, item, units units_orig,
units - lag(units,1,0) over (partition by item order by trans_date) units
from tab),
tot as (
select trans_date, sum(units) total_unit
from clean
group by trans_date)
select trans_date,
sum(total_unit) over (order by trans_date) total_unit_cum
from tot
order by 1
;
TRANS_DATE TOTAL_UNIT_CUM
------------------- --------------
05.11.2018 00:00:00 7
09.11.2018 00:00:00 14
16.11.2018 00:00:00 27
21.11.2018 00:00:00 29
29.11.2018 00:00:00 44
选项,因此可以达到目的:
expose_nil