-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible belongs_to improvement #36
Comments
I'm open to a PR. I'm fine with what you've laid out and my only real reservation is that i just don't love |
what happens if the comments schema does not specify type? schema "comments" do
belongs_to :post, Post
end the existing code should infer all of the TypeID information using the |
In that case Ecto assumes What would an acceptable solution look like? I've just ran into this issue an can write a PR |
I started drafting a solution here https://github.com/sloanelybutsurely/typeid-elixir/pull/40/files and the following approach seems to work: To get the For If you think the solution makes sense I can polish the PR |
Are either of you able to provide a minimal reproducing project to share? My guess is the issues you're running into have something to do with how the project is configured (the values of |
I haven't been able to try without specifying |
I've built one in this repo: https://github.com/lurodrigo/typeid_blog
|
I can confirm that I also run into this issue when only using |
thanks for the input here. i'm investigating this issue and coming up with some potential solutions. |
I just started to work with adding TypeIDs to my app and immediately ran into issues with
belongs_to
. I've looked at the other issues and I did get it to work by usingdefine_field: false
and a separatefield :thing_id
. It did however feel like it should work to just dobut when I tried that I got an error about
type
was only allowed to be:uuid
or:string
. Without usingtype: TypeID
I got an error aboutvalue #TypeID<"aaa_01j95zhepsf75rfymj6egjqg9m"> in where cannot be cast to type :integer in query
.Digging further I realized that when using
type
param tobelongs_to
, the value fortype
is included in the call toTypeID.init
. This means when usingtype: TypeID
,dump
will try to see what database type it should convert itself to, but the type isTypeID
, which is the Ecto custom type, not the database type.I have a solution to this which changes the name of the
type
parameter tocolumn_type
, so the primary key definitions becomeand the belongs_to definitions becomes
With a default of :uuid, the
column_type
can also be dropped.I'm guessing this is something around the differences of how Ecto handles a
ParameterizedType
when used as a normal field and an association. Would you be interested in a PR for this if I clean it up? Or am I missing something here that makes it a bad idea?The text was updated successfully, but these errors were encountered: