I feel like there should be an easy way to do this, without creating a (relatively complicated) custom validation. But after combing the docs and forum, I’m thinking perhaps not…
Here’s a somewhat simplified case.
I have two resources, a sprint and an activity.
sprint’s have a date range, e.g., sprint.start_date
and sprint.end_date
.
Activities belong to sprints, and have a date, activity.date
.
def Sprint do
attributes do
attribute :start_date, :date, allow_nil? false
attribute :end_date, :date, allow_nil? false
end
end
def Activity do
attributes do
attribute :date, :date, allow_nil? false
end
belongs_to :sprint, Sprint do
attribute_writable? true
allow_nil? false
end
end
The desired outcome is that an activity’s date must fall within the start and end dates of its sprint.
It seems I should be able to do something like the following – but, I haven’t been able to figure out how.
# This absolutely won't even compile, but it expresses the idea I'm after:
validations do
validate compare(:date, greater_than_or_equal_to: :sprint.start_date)
validate compare(:date, less_than_or_equal_to: :sprint.end_date)
end
Maybe I’m expecting too much and I need to do a custom validator, but thought I’d post the question. (I’m also just getting back into Ash… just upgraded a small project from 2.4 to 3.4, and really dusting off some very, very dusty recollection of how it all works…)
If there is a way to achieve the above without dropping into complicated (potentially atomic) validations and atomic_ref()
and the like… well, I’d love some pointers. Not up to speed on atomics yet… Thanks!