Skip to content

Commit 58d68ee

Browse files
authored
Add docs for not/1 (#3745)
1 parent 291ae8d commit 58d68ee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/ecto/query/api.ex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ defmodule Ecto.Query.API do
107107

108108
@doc """
109109
Unary `not` operation.
110+
111+
It is used to negate values in `:where`. It is also used to match
112+
the assert the opposite of `in/2`, `is_nil/1`, and `exists/1`.
113+
For example:
114+
115+
from p in Post, where: p.id not in [1, 2, 3]
116+
117+
from p in Post, where: not is_nil(p.title)
118+
119+
# Retrieve all the posts that doesn't have comments.
120+
from p in Post,
121+
as: :post,
122+
where:
123+
not exists(
124+
from(
125+
c in Comment,
126+
where: parent_as(:post).id == c.post_id
127+
)
128+
)
129+
110130
"""
111131
def not(value), do: doc! [value]
112132

0 commit comments

Comments
 (0)