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

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
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
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement