propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 398 forks source link

avoid name collision in cross ref relations #1963

Closed mringler closed 10 months ago

mringler commented 1 year ago

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 commented 1 year ago

Codecov Report

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

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

:mega: 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 ```diff @@ 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%)` | :arrow_up: | | 7.4 | `89.25% <100.00%> (+0.69%)` | :arrow_up: | | agnostic | `67.42% <71.42%> (+0.12%)` | :arrow_up: | | mysql | `69.79% <100.00%> (+0.71%)` | :arrow_up: | | pgsql | `69.83% <100.00%> (+0.71%)` | :arrow_up: | | sqlite | `67.79% <100.00%> (+0.71%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://codecov.io/gh/propelorm/Propel2/pull/1963?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm) | Coverage Δ | | |---|---|---| | [.../Propel/Generator/Builder/Om/AbstractOMBuilder.php](https://codecov.io/gh/propelorm/Propel2/pull/1963?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvQnVpbGRlci9PbS9BYnN0cmFjdE9NQnVpbGRlci5waHA=) | `96.75% <100.00%> (+0.04%)` | :arrow_up: | | [src/Propel/Generator/Model/Table.php](https://codecov.io/gh/propelorm/Propel2/pull/1963?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvTW9kZWwvVGFibGUucGhw) | `90.60% <100.00%> (+0.04%)` | :arrow_up: | ... and [20 files with indirect coverage changes](https://codecov.io/gh/propelorm/Propel2/pull/1963/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm) Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm)

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