elixir-sqlite / ecto_sqlite3

An Ecto SQLite3 adapter.
https://hexdocs.pm/ecto_sqlite3
MIT License
300 stars 45 forks source link

on_delete setting is casting uuids, which makes queries fail #119

Closed LostKobrakai closed 1 year ago

LostKobrakai commented 1 year ago
Repo.delete_all(Dresser.Schema.PieceImage |> where(piece_id: ^piece.id))

The above results in the following (working) query.

DELETE FROM "piece_images" AS p0 WHERE (p0."piece_id" = ?) ["f1511051-0079-448b-b0b9-562d71b0ad96"]

But deleting a (parent) record, where on_delete: :delete_all is set on a relationship (many_to_many here) I get the following query, which doesn't work:

DELETE FROM "piece_images" AS p0 WHERE (p0."piece_id" = CAST(? AS BLOB)) ["7e162d9e-3e22-4846-adf1-b4abd25966ac"]

The latter query works with the binary_id_type: :string setting (still casting, but to TEXT), but using binary_id_type: :binary it doesn't work.

exqlite 0.13.5 / ecto_sqlite3 0.10.3

warmwaffles commented 1 year ago

@LostKobrakai can you provide me a minimum config to reproduce this? I'm going to chuck this into a test.

LostKobrakai commented 1 year ago

@warmwaffles see https://github.com/LostKobrakai/dresser_repro/commit/f24ebffc6c5c2e1be848911efc1dbc4ea026ec14

warmwaffles commented 1 year ago

Awesome, I'll get to this in a bit. 👍🏻

warmwaffles commented 1 year ago

@LostKobrakai I think this is effecting more than just delete_all. That where clause reuses the same code path.

warmwaffles commented 1 year ago

I haven't forgotten about this. I did some test refactoring and broke them up into more maintainable chunks. I need to get this recreated.

warmwaffles commented 1 year ago

@LostKobrakai This is fixed in #121 by @greg-rychlewski. I'll be releasing this shortly under the v0.10.4 version.