VincentBlackdot

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

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

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.

Where Next?

Popular in Questions Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

We're in Beta

About us Mission Statement