Elixir 在EXTO中组合两个where查询

Elixir 在EXTO中组合两个where查询,elixir,phoenix-framework,ecto,Elixir,Phoenix Framework,Ecto,我正在尝试创建一个EXTO查询,当两个where查询都满足时,该查询将返回一个结果。当我运行应用程序时,我得到错误函数nil.title/0未定义或私有。这是因为我没有正确的查询吗?我想要一个和两个在哪里 def next_prod do Post |> where(postStatus: "published") |> where(next_prod: "yes") |> Repo.one() end SQL查询 您将看到有一条记录应该与EXTO查询匹配 iex(1)&

我正在尝试创建一个EXTO查询,当两个where查询都满足时,该查询将返回一个结果。当我运行应用程序时,我得到错误
函数nil.title/0未定义或私有
。这是因为我没有正确的查询吗?我想要一个和两个在哪里

def next_prod do
  Post |> where(postStatus: "published") |> where(next_prod: "yes") |> Repo.one()
end
SQL查询

您将看到有一条记录应该与EXTO查询匹配

iex(1)> Codsonline.Repo.query("SELECT * FROM posts")
[debug] QUERY OK db=3.0ms queue=0.1ms
SELECT * FROM posts []
{:ok,
 %Postgrex.Result{columns: ["id", "title", "snippet", "body", "slug", "mainImg",
   "thumbImg", "postStatus", "showStatus", "inserted_at", "updated_at",
   "next_prod"], command: :select, connection_id: 13732, num_rows: 1,
  rows: [[8, "Blackadder Goes Forth",
    "“Blackadder Goes Forth ” is the fourth and final part of the Blackadder series . A theatrical Dramatisation inspired by the TV episodes. Follow the Wit and Sarcasm of Captain BlackAdder  in Oscar Wilde language.",
    "27th January – 03rd February 2018\r\nPlayhouse Theatre, Cheltenham\r\n\r\n \r\n\r\nEpisodes:\r\n‘Corporal Punishment‘ (Episode 2)\r\n‘Private Plane‘ (Episode 4)\r\n‘Goodbyeee‘ (Episode 6)\r\n\r\nDirected by Nick Tobias & Liz White\r\n\r\n \r\n\r\nCast List:\r\n\r\nCaptain Edmund Blackadder – Chris Hannant\r\nPrivate S Baldrick – Matt Wilson\r\nLt. Hon. George Colthurst St Barleigh – UNCAST\r\nGeneral Sir Anthony Cecil Hogmanay Melchett – Jason Blackburn\r\nCaptain Kevin Darling – Jack Homer\r\nSquadron Commander the Lord Flashheart – Michael Fay\r\nField Marshall Sir Douglas Haig – Will Browne\r\nBaron Von Richthoven – Robert Barton-Ancliffe\r\nBob ‘Bobbie’ Parkhurst – Sarah Bottomley\r\n\r\nEnsemble – Ben Wilson (Sergeant Jones), Oliver Chapman (Gerhardt), Michael Sheldrick (Perkins), Steve Scott, Matthew Morris",
    "blackadder-goes-forth", ".", ".", "published", "Future",
    {{2017, 11, 18}, {22, 36, 19, 408441}},
    {{2017, 11, 18}, {23, 3, 42, 816258}}, "Yes"]]}}

该错误不是来自这行代码。您的代码很好,这两个子句将由EXTO进行and'd。该错误表示您试图在某个地方调用
nil.title

iex(1)> nil.title
** (UndefinedFunctionError) function nil.title/0 is undefined or private
    nil.title()
我猜您在这个函数的返回值上调用了
.title
,但实际上数据库中没有与这两个条件匹配的记录。你应该使用
Repo.one如果要确保记录存在。或者,如果要处理记录不存在的情况,请在以下情况下使用

if record = Thing.next_prod do
  # record exists
else
  # it doesn't
end

您想要
next\u prod=“yes”和next\u prod=“no”
?那跟什么都不匹配。顺便说一句,您的语法是正确的。该错误来自其他地方。ha复制粘贴错误。刚刚更正了opposts中的字符串,确保记录存在,我可以在
posts=Blog.list_posts()的索引中看到它
我可以看到一条记录,这两条where子句都是正确的。能否将该命令的输出和运行此函数时在日志中得到的SQL查询添加到问题中?在查询中使用“是”,数据库中的字段为“是”。你能试着把它们做成同样的箱子吗?该死。就这样。案例不匹配。