Skip to content

Commit

Permalink
docs: mention that update expressions are composable (#4386)
Browse files Browse the repository at this point in the history
  • Loading branch information
saveman71 authored Feb 29, 2024
1 parent 7c64af6 commit f7f0d00
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/ecto/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,19 @@ defmodule Ecto.Query do
from(u in User, update: [pull: [tags: "not cool"]])
## Composable
Remember that all query expressions are composable, so you can use `update`
multiple times in the same query to merge the update expressions:
new_name = "new name"
User
|> update([u], set: [name: fragment("upper(?)", ^new_name)])
|> update([u], set: [age: 42])
This can be useful to compose updates from different functions
or when mixing interpolation, such as `set: ^updates`, with regular
query expressions, such as `set: [age: u.age + 1]`.
"""
defmacro update(query, binding \\ [], expr) do
Builder.Update.build(query, binding, expr, __CALLER__)
Expand Down

0 comments on commit f7f0d00

Please sign in to comment.