I'm relatively new to the language, and have already read the differences between the require and import keywords. Nevertheless I can't seem to understand the following behavior while using Ecto.
So, I want to extract a fragment that's commonly used to get a value from a json field. Reading the Ecto docs I understand that in order to extract a fragment I have to wrap it on a dynamic macro. So I'm trying to implement it like this:
defmodule Foo do
require Ecto.Query
...
defp foo_fragment() do
dynamic([t], fragment("?.json->>'foo'", t))
end
end
To which I get the following warning
variable "t" does not exist and is being expanded to "t()", please use parentheses to remove the ambiguity or change the variable name
Which seems reasonable enough, but isn't mentioned on the Ecto documentation. Looking for answers I found this SO question where is recommended to use import Ecto.Query. I also noticed that it's used that way on the Ecto docs examples (probably for aesthetic reasons though).
To my surprise upon trying it, the warning on the previous code it's gone.
Is there something I'm missing regarding these keywords? I thought both were equivalent regarding the usage of macros, require being a more conservative approach as to keeping namespaces apart. Thanks!