matt1
January 16, 2019, 12:35pm
#1
This may be a newbie question, sorry about that, but i can’t figure it out.
Im trying to make a simple thing
import Ecto.Query
...
filter = %{key: "tags", value: "aaa"}
value = filter[:value]
fragment(" '?' =ANY (tags)", value)
But I get every time undefined function fragment/2
I tried importing or using API
Builder
etc but without result.
Anyone has a full example? (I’m using ":ecto, "3.0.6"
thanks in advance
jdj_dk
January 16, 2019, 12:55pm
#2
This may be a newbie question, sorry about that, but i can’t figure it out.
No need for apologies. I assume it is because you need to use the fragment inside a Query. Can you show the entire function?
Here is an example
from p in Post,
where: is_nil(p.published_at) and
fragment("lower(?)", p.title) == ^title
from https://hexdocs.pm/ecto/Ecto.Query.html#module-fragments
2 Likes
You can also use dynamic if you need to use fragment outside Query
2 Likes
matt1
January 16, 2019, 1:33pm
#4
matt1
January 16, 2019, 1:34pm
#5
I use dynamic, but i need a query like
SELECT * from services where 'xxxx' =ANY(tags)
If you want to use fragment outside Query you need to wrap it inside dynamic, I don’t see you doing that in your gist. What I mean is something like this dynamic([d], fragment("?=ANY (tags)", d.some_field))
3 Likes
matt1
January 16, 2019, 1:44pm
#7
perfect! that was the solution! thank you so much!