【发布时间】:2017-09-29 02:23:28
【问题描述】:
我不知道如何将 SQL 语句翻译成 Ecto。
凤凰设置
mix phx.gen.html Location Country countries name
mix phx.gen.html Location FederalState federal_states name
mix phx.gen.html Calendar Day days date_value:date
mix phx.gen.html Calendar Period periods name
starts_on:date
ends_on:date
country_id:references:countries
federal_state_id:references:federal_states
mix pix.gen.html Calendar Slot slots day_id:references:days
period_id:references:periods
SQL 语句
SELECT days.date_value, periods.name FROM days
LEFT OUTER JOIN slots ON (days.id = slots.day_id)
LEFT OUTER JOIN periods ON (slots.period_id = periods.id and
(periods.country_id = 1 OR
periods.federal_state_id = 5))
WHERE days.date_value >= '2017-01-01' AND
days.date_value <='2017-12-31'
ORDER BY days.date_value;
是否可以用 Ecto 函数替换这条 SQL 语句?
【问题讨论】:
-
join 函数接受一个参数,该参数用于指定您需要什么样的连接。除此之外,很高兴在我们为您完成所有工作之前看看您尝试了什么。
-
我通过 learningelixir.joekain.com/none-of-the-associations-in-ecto 工作,但无法使用 Ecto。
标签: elixir phoenix-framework ecto