Filter function do not work...What am I missing? (Returns empty)

defmodule Ampldev.Syllabuses.GySeCourse do
# This turns this module into a resource
use Ash.Resource,
data_layer: Ash.DataLayer.Ets

attributes do
attribute :code, :string do
primary_key? true
allow_nil? false
end

attribute :name, :string do
allow_nil? false
end

attribute :central_content, {:array, :string}
end

actions do
defaults [:read]

read :search_course_name do
argument :name, :string do
end

filter expr(contains(^arg(:name), name))
end
end

code_interface do
define_for Ampldev.Syllabuses
define :search_course_name, args: [:string]
end
end
defmodule Ampldev.Syllabuses.GySeCourse do
# This turns this module into a resource
use Ash.Resource,
data_layer: Ash.DataLayer.Ets

attributes do
attribute :code, :string do
primary_key? true
allow_nil? false
end

attribute :name, :string do
allow_nil? false
end

attribute :central_content, {:array, :string}
end

actions do
defaults [:read]

read :search_course_name do
argument :name, :string do
end

filter expr(contains(^arg(:name), name))
end
end

code_interface do
define_for Ampldev.Syllabuses
define :search_course_name, args: [:string]
end
end
9 Replies
sevenseacat
sevenseacat3y ago
what SQL is getting generated? what data should be getting returned?
maxmannen
maxmannenOP3y ago
I have an ETS-table with courses (name, code etc). Want to find a course by part of its name.
sevenseacat
sevenseacat3y ago
oh ETS, I missed that
ZachDaniel
ZachDaniel3y ago
Your argument order is backwards Contains expect the thing that contains the stuff to be the first argument, and the thing you want to be contained as the second. I.e contains(“foobar”, “oba”) is true But contains(“oba”, “foobar”) is not
maxmannen
maxmannenOP3y ago
I caught that one actually. The error was the way I called the action...my editor suggested a string value instead of (:read, %{name="..."}) Still have things to learn about Ash...
ZachDaniel
ZachDaniel3y ago
Is that the syntax you used? name=“” Anyway, glad you figured it out 🙂
maxmannen
maxmannenOP3y ago
search_course_name I mean. Thanks !
ZachDaniel
ZachDaniel3y ago
ohhh, okay 🙂
sevenseacat
sevenseacat3y ago
ooh that's a tricky one, I would have expected it to be OP's way around wait no.... I confused myself. not the first time

Did you find this page helpful?