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

avoid name collision in cross ref relations #1963

Conversation

mringler
Copy link
Contributor

@mringler mringler commented Apr 23, 2023

Fixes #941

When you have three FKs on a cross-reference table, Propel will generate methods on the referenced tables, where the name uses a combination of the other two FKs. For example, if a cross-reference table has three FKs to the tables A, B and C, Propel generates a method clearABs() on table C. The methods are clear*, init*, get*, set*, count*, doAdd* and remove*.

This produces collisions when the name of the cross-reference table is a combination of the names of two of the referenced tables. In above example, that would happen when the cross-reference table is named AB. (Somewhat unfortunately, this is the name suggested in the documentation.
In this case, Propel adds some methods with the same name, once where it handles the cross-reference table (clearABs to clear associated elements in the cross ref table), and once again where it handles the tables connected by the cross-reference table (clearABs to clear associated As and Bs). This leads to an exception.

The name for the cross-ref relations is generated in AbstractOmBuilder::getCrossFKsPhpNameAffix(), this change tests whether the current table has a FK relation to another table with the same name, and if so, prefixes the relation name with Cross. The above method would then be called clearCrossABs().

From what I can see, this only affects names that could not occur before because of the error, so I don't think this affects BC.

@codecov-commenter
Copy link

codecov-commenter commented Apr 23, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.69 🎉

Comparison is base (011aaa7) 88.56% compared to head (2e9e80f) 89.25%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1963      +/-   ##
============================================
+ Coverage     88.56%   89.25%   +0.69%     
- Complexity     8051     8056       +5     
============================================
  Files           243      232      -11     
  Lines         24590    24552      -38     
============================================
+ Hits          21777    21915     +138     
+ Misses         2813     2637     -176     
Flag Coverage Δ
5-max 89.25% <100.00%> (+0.69%) ⬆️
7.4 89.25% <100.00%> (+0.69%) ⬆️
agnostic 67.42% <71.42%> (+0.12%) ⬆️
mysql 69.79% <100.00%> (+0.71%) ⬆️
pgsql 69.83% <100.00%> (+0.71%) ⬆️
sqlite 67.79% <100.00%> (+0.71%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../Propel/Generator/Builder/Om/AbstractOMBuilder.php 96.75% <100.00%> (+0.04%) ⬆️
src/Propel/Generator/Model/Table.php 90.60% <100.00%> (+0.04%) ⬆️

... and 20 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mringler mringler force-pushed the bugfix/avoid_cross_ref_relation_name_collisions branch from 2e9e80f to 03ff801 Compare September 5, 2023 13:09
@gechetspr gechetspr merged commit 8117e54 into propelorm:master Nov 28, 2023
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional foreign keys on cross-reference table produce duplicate query methods
5 participants