wintermeyer
How can I do a custom validation in the following resource to make sure that the attribute use_by_date is today or later but not in the past?
defmodule App.Shop.Product do
use Ash.Resource, data_layer: Ash.DataLayer.Ets
attributes do
uuid_primary_key :id
attribute :name, :string do
allow_nil? false
constraints min_length: 3
end
attribute :price, :decimal
attribute :use_by_date, :date do
allow_nil? false
end
end
actions do
defaults [:create, :read]
end
end
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
What you’re looking for is validations. I don’t think our built in validations will do datetime comparisons, but you can do it with a custom validation.
EDIT: The validations guide is here: Validations — ash v3.29.3
wintermeyer
For the archive and Google: The code in the resource would look like this.
sheerlox
I had to tackle the same issue today and adapted the code from Ash’s
compare()validation to work withDatestructs. It has the same behavior, only the accepted argument types changed.I’m posting it for the record, also it can be easily adapted to work with
DateTimeinstead.@zachdaniel I was wondering if maybe it would be interesting to cast to the expected data types before running the validations because I think that would allow the built-in
comparevalidation to work withDateandDateTime? I’m not sure what that could imply, so I’m bringing up the idea in case it’s a good oneEDIT: my bad, seems like the attribute is already cast in the validator. Not sure why using the classic validation with
Date.utc_now()wasn’t working thenEDIT 2:
Compshould support theDatestruct so not sure what the issue might be when using the built-incompare, looks like it should work.Anyway nothing urgent, 3.0 is a much more serious topic
zachdaniel
So, not sure why the builtin one wouldn’t be working, but you need to be careful with
Date.utc_today()like that. That will be referring to the day your app was compiledMake sure to use
&Date.utc_today/0