Skip to content
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

AssociateAction derives wrong inverse relationship name #14090

Open
zepfietje opened this issue Aug 29, 2024 · 3 comments · May be fixed by #14145
Open

AssociateAction derives wrong inverse relationship name #14090

zepfietje opened this issue Aug 29, 2024 · 3 comments · May be fixed by #14145
Labels
bug Something isn't working
Milestone

Comments

@zepfietje
Copy link
Member

zepfietje commented Aug 29, 2024

Inverse relationship is derived as plural of the model name while it should be singular.

Donate 💰 to fund this issue

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar
@zepfietje zepfietje added the bug Something isn't working label Aug 29, 2024
@zepfietje zepfietje added this to the v3 milestone Aug 29, 2024
@BrianM0330
Copy link

I found another potentially related issue with table prefixes.

AssociateAction and AttachAction are building the wrong name inside of the SQL query with a database prefix. When using ->preloadRecortSelect() the records do load up with no issue but when using the search function the Resource breaks. I did some debugging and noticed that the SQL queries are being misconstructed because they aren't using the table prefix.

I have a prefix my_prefix inside of config/database.php and AssociateAction seems to use table_name instead of my_prefix_table_name causing an error inside of the relationship modals.

ERROR:  missing FROM-clause entry for table "my_table" at character 106
STATEMENT:  select "my_prefix_table_name"."title", "my_prefix_table_name"."id" from "my_prefix_table_name" where (lower(table_name.title::text)::text like $1) and not exists (select * from "my_prefix_courses" where "my_prefix_table_name"."course_id" = "my_prefix_courses"."id" and "my_prefix_courses"."id" = $2) order by "my_prefix_table_name"."title" asc limit 50

The issue is in the call to lower(table_name.title) where it should be lower("my_prefix_table_name".title)

Screenshot 2024-08-29 at 5 01 20 PM

@pelmered
Copy link

pelmered commented Sep 4, 2024

I made a PR with a fix.

A workaround for the moment is to add this to the RelationManager class:

    protected static ?string $inverseRelationship = 'singlular_relation_name';

@zepfietje
Copy link
Member Author

Thanks for working on this, @pelmered!
I was planning to create a PR today, but will now request Dan's review on your PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

3 participants