Closed doughsay closed 3 years ago
Thats definitely curious and I wonder if it is indeed an Ecto bug. I'll do some digging. In the meantime I can workaround this since I need to push an update today for issue #14.
Thanks much for the issue and sorry for the inconvenience. Moving to a parameterised type has proved more problematic on edge cases than expected.
Turns out I can't work around this. Adding type/0
to the composite type seems to make Ecto think its a non-parameterised type and therefore other bad things happen.
Confirmed it was an Ecto bug which is now fixed on the main branch. I confirmed is works in my tests.
I expect this will be fixed when Ecto 3.6 comes out. Until then, if there is no other way, I recommend you use ecto
directly from GitHub using:
# Your query should look like this
# init_options is either `[]` or a keyword list of options
# you would pass to the `:field` definition on an ecto
# schema
query =
from(
organization in "organizations",
select: %{
total: type(sum(organization.payroll),
^Ecto.ParameterizedType.init(Money.Ecto.Composite.Type, init_options)
)
}
)
# Which basically is the same as:
query =
from(
organization in "organizations",
select: %{
total: type(sum(organization.payroll),
^{:parameterized, Money.Ecto.Composite.Type, []}
)
}
)
# mix.exs
def deps do
...
{:ecto, github: "elixir-echo/ecto", override: true},
...
end
Closing this issue for now, let me know if there is anything else I can help with.
Hi there,
I just tried upgrading to
ex_money_sql
~> 1.4 and I have compilation errors in my application now. I think what's going on is that the Ectotype
function from the Query API doesn't support parameterized types, but I'm not quite sure... If this is an issue withecto
itself, I can open an issue with them as well.I've created a minimal repo to demonstrate the issue: https://github.com/doughsay/ecto_money The details are in the readme, but I'll duplicate them here for convenience.
Expected:
This is the response you get when using
ex_money_sql
== 1.3.1Actual:
Using
ex_money_sql
~> 1.4, with the new parameterized type, we get a compilation error:Workarounds
You can remove the casting, but then you get back a tuple instead of a Money struct.
Results in: