nyakio

nyakio

I have a list of records that are to be sorted by the inserted_at column, and I would like to test the sorting functionality. In Ecto, I would create a list of the records and use Repo.update to update the inserted_at column with a calculated value so that the records have different timestamps.

I was able to work this out when I made the inserted_at attributed writable and passed it as an attribute to the update action

I would like to have the inserted_at field as a private attribute so that users cannot update it via the form, but this approach does not return updated values.

In my resource I have:

attribute :inserted_at, :utc_datetime_usec do
  writable? true
  default &DateTime.utc_now/0
  match_other_defaults? true
  allow_nil? false
end

...
update :update do
  argument :inserted_at, :utc_datetime_usec

  accept [:email, :language, :creator_id, :tenant_id, :inserted_at]

  primary? true
end

And In the test I have:

for invitation <- invitations, i <- 1..length(invitations) do
  invitation
  |> Ash.Changeset.for_update(
      :update,
      %{},
        private_arguments: %{inserted_at: time_before_or_after(-i * 12000)},
      authorize?: false
    )
    |> Ash.update!()
end

Showing Posts 1 to 2

barnabasJ

barnabasJ

Ash Core Team

Hi

You still need to do something with the argument. That’s probably not precisely clear just by reading the Privat Inputs section of the docs. But an argument by itself is not doing anything.

update :update do
  argument :inserted_at, :utc_datetime_usec

  accept [:email, :language, :creator_id, :tenant_id, :inserted_at]

  primary? true

  change fn changeset, _context -> 
    case Ash.Changeset.get_argument(changeset, :inserted_at) do
      nil -> changeset
      datetime -> Ash.Changeset.change_atttrribute(changeset, :inserted_at, datetime)
    end
  end
end
barnabasJ

barnabasJ

Ash Core Team

I would probably go with the context route described in the next section of the Docs.
For example, if you use AshGraphql, the argument would appear in the API. You could set it to public?: false to hide it from that layer though. But then you don’t have a good way to supply it yourself if needed.

But if you go the context route, you could supply values to AshGraphl in a plug or middleware that would be passed on to the actions.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews