-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
Non-standard id via primary_key
option on Belongs To field not respected
#3413
Comments
I have worked around this for now with a method like this on my Post object:
|
Hi @therabidbanana thanks for opening the issue. Could you please create a minimal reproduction repository? Here's a quick command that will help you generate a new Avo app in no-time. Thank you! |
Sure! Here's a repository reproducing the issue. I went with SQLite which doesn't have native uuid types, but that's kind of a side concern so strings are fine here. The point is that primary_key is not used as expected so the user_id is being set to the integer rather than the string column. https://github.com/therabidbanana/avo-repro-3413 In this screenshot, we'd expect proper functioning to either be:
Instead what happens is it sends the integer id and doesn't look up the primary_key desired, resulting in a "user must be specified" error because user_id mismatches here. |
Thanks for the repo, @therabidbanana! It was helpful and made reproducing the issue quick and easy. While working through it, I put together this PR which solves the issue. However, tests are currently failing on polymorphic associations. The PR will stay in draft for a while, so feel free to refine it if you'd like to contribute. |
Describe the bug
We have a table that has an integer id (deprecated) and a uuid used for all new tables. This is easy to define in the activerecord relationship via
primary_key
:But the Avo belongs to field for this relationship still tries to save using the
#id
method. Depending on if the id field exists on the table this will either generate a NoMethodError or, in our case since we actually have both, using an invalid integer type id, silently failing.Steps to Reproduce
Steps to reproduce the behavior:
field :user, as: :belongs_to
Expected behavior & Actual behavior
Observe
id
param is sent rather thanuuid
Models and resource files
System configuration
Avo version:
= 3.13.7
Rails version:
= 7.2.1.2
Ruby version:
License type:
Additional context
My best guess following code path is that it looks like id is assumed to the the primary key here, but reflections should be used like they are for the foreign key option:
https://github.com/avo-hq/avo/blob/main/lib/avo/fields/belongs_to_field.rb#L219
Impact
Urgency
The text was updated successfully, but these errors were encountered: