VincentBlackdot
Update Current Page data pull by Scrivener
i want to update only the current records being viewed by the user. but my current query is updating every record matching in the db.
how do i only apply this affect to only records that have been pulled by scrivener that the user is viewing
eg.
if my current table is only showing 10records on those 10 should change to there status to read
here is my query.
defmodule Messages do
def mark_status_updated do
MyApp.Messages.where(status: "PENDING" )
|> case do
[] -> []
pending_sms ->
Enum.map(pending_sms, fn smses ->
MyApp.Messages.update(smses, status: "READ")
end)
end
end
end
Marked As Solved
baldwindavid
It appears that in one example a Scrivener.Page struct is being passed to update_status and, in the other, single integers rather than the expected List of integers. But, to @dimitarvp 's point, inspecting the query with his example code will likely uncover the issue quickly. Additionally, IO.inspect can help a lot in debugging.
For instance, it could be added to update_status…
def update_status(ids) do
IO.inspect(ids)
Myschema
|> where([a], a.id in ^ids and a.status == "PENDING")
|> Repo.update_all(set: [status: "READ"])
end
It can also be added anywhere within a pipeline and multiple times…
def slogs(search_params, page, size) do
MySchema
|> handle_report_filter(search_params)
|> order_by(desc: :status)
|> compose_report_select()
|> Repo.paginate(page: page, page_size: size)
|> IO.inspect()
|> update_status()
end
Exercise the code in your tests or even the running app and the inspected values will appear in the terminal.
Also Liked
dimitarvp
I would do this to try and understand what’s wrong:
Myschema
|> where([a], a.id in ^ids and a.status == "PENDING")
|> Ecto.Adapters.SQL.to_sql()
And take it from there.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








