typeid-elixir icon indicating copy to clipboard operation
typeid-elixir copied to clipboard

Improvements for Ecto

Open andrewtimberlake opened this issue 2 years ago • 1 comments

I was trying to migrate from bigint ids to TypeID I came across a few problems because I need to have TypeID working during interim steps.

  1. You can’t use TypeID as a standard, non primary-key field (this would fail to pick up the prefix)
schema "table" do
  field :uuid, TypeID, prefix: "user", type: :binary_id
end
  1. You can’t set the foreign key type aside from using @foreign_key_type TypeID
belongs_to :model, Model, type: TypeID

This pull request addresses both usages I didn’t see any Ecto tests, so I haven’t provided tests.

andrewtimberlake avatar Sep 20 '23 09:09 andrewtimberlake

hi! thanks for taking the time to contribute. i'll need a moment to review this more thoroughly but i did have some immediate feedback for you:

2. You can’t set the foreign key type aside from using @foreign_key_type TypeID

you can do this using define_field: false on the belongs_to and defining the foreign key field manually. See https://github.com/sloanelybutsurely/typeid-elixir/issues/20#issuecomment-1635829743 for a more complete example.

sloanelybutsurely avatar Sep 20 '23 15:09 sloanelybutsurely