From 5c9bef52807c0ddfc94d2a2fec7cb3b07c958504 Mon Sep 17 00:00:00 2001 From: kasparsj Date: Fri, 5 Jun 2020 14:57:33 +0300 Subject: [PATCH 1/6] allow to use non-primary columns in crossref tables --- src/Propel/Generator/Model/CrossForeignKeys.php | 4 ++-- src/Propel/Generator/Model/ForeignKey.php | 4 ++-- src/Propel/Generator/Model/Table.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Propel/Generator/Model/CrossForeignKeys.php b/src/Propel/Generator/Model/CrossForeignKeys.php index 00d2d695a5..e93907ab9f 100644 --- a/src/Propel/Generator/Model/CrossForeignKeys.php +++ b/src/Propel/Generator/Model/CrossForeignKeys.php @@ -130,9 +130,9 @@ public function getIncomingForeignKey() * @param ForeignKey $fk * @return bool */ - public function isAtLeastOneLocalPrimaryKeyNotCovered(ForeignKey $fk) + public function isAtLeastOneLocalColumnNotCovered(ForeignKey $fk) { - $primaryKeys = $fk->getLocalPrimaryKeys(); + $primaryKeys = $fk->getLocalColumnObjects(); foreach ($primaryKeys as $primaryKey) { $covered = false; foreach ($this->getCrossForeignKeys() as $crossFK) { diff --git a/src/Propel/Generator/Model/ForeignKey.php b/src/Propel/Generator/Model/ForeignKey.php index 0337d413c7..ce5e32df11 100644 --- a/src/Propel/Generator/Model/ForeignKey.php +++ b/src/Propel/Generator/Model/ForeignKey.php @@ -765,9 +765,9 @@ public function isAtLeastOneLocalColumnRequired() * * @return boolean */ - public function isAtLeastOneLocalPrimaryKeyIsRequired() + public function isAtLeastOneLocalColumnIsRequired() { - foreach ($this->getLocalPrimaryKeys() as $pk) { + foreach ($this->getLocalColumnObjects() as $pk) { if ($pk->isNotNull() && !$pk->hasDefaultValue()) { return true; } diff --git a/src/Propel/Generator/Model/Table.php b/src/Propel/Generator/Model/Table.php index e89316c3bb..aca4c68376 100644 --- a/src/Propel/Generator/Model/Table.php +++ b/src/Propel/Generator/Model/Table.php @@ -821,8 +821,8 @@ public function getCrossFks() if ($refFK->getTable()->isCrossRef()) { $crossFK = new CrossForeignKeys($refFK, $this); foreach ($refFK->getOtherFks() as $fk) { - if ($fk->isAtLeastOneLocalPrimaryKeyIsRequired() && - $crossFK->isAtLeastOneLocalPrimaryKeyNotCovered($fk)) { + if ($fk->isAtLeastOneLocalColumnIsRequired() && + $crossFK->isAtLeastOneLocalColumnNotCovered($fk)) { $crossFK->addCrossForeignKey($fk); } } From 27810267f4d047595a6d6f35e1974d8bcb8500f0 Mon Sep 17 00:00:00 2001 From: kasparsj Date: Thu, 29 Oct 2020 11:51:07 +0200 Subject: [PATCH 2/6] revert method names --- src/Propel/Generator/Model/CrossForeignKeys.php | 2 +- src/Propel/Generator/Model/ForeignKey.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Propel/Generator/Model/CrossForeignKeys.php b/src/Propel/Generator/Model/CrossForeignKeys.php index a26d5fd4cc..8e5078d981 100644 --- a/src/Propel/Generator/Model/CrossForeignKeys.php +++ b/src/Propel/Generator/Model/CrossForeignKeys.php @@ -132,7 +132,7 @@ public function getIncomingForeignKey() * * @return bool */ - public function isAtLeastOneLocalColumnNotCovered(ForeignKey $fk) + public function isAtLeastOneLocalPrimaryKeyNotCovered(ForeignKey $fk) { $primaryKeys = $fk->getLocalColumnObjects(); foreach ($primaryKeys as $primaryKey) { diff --git a/src/Propel/Generator/Model/ForeignKey.php b/src/Propel/Generator/Model/ForeignKey.php index 74563b7f81..e334f180fa 100644 --- a/src/Propel/Generator/Model/ForeignKey.php +++ b/src/Propel/Generator/Model/ForeignKey.php @@ -800,7 +800,7 @@ public function isAtLeastOneLocalColumnRequired() * * @return bool */ - public function isAtLeastOneLocalColumnIsRequired() + public function isAtLeastOneLocalPrimaryKeyIsRequired() { foreach ($this->getLocalColumnObjects() as $pk) { if ($pk->isNotNull() && !$pk->hasDefaultValue()) { From d75492deeafa23c607510972edd25cdf1de2e230 Mon Sep 17 00:00:00 2001 From: vol4onok Date: Thu, 21 Mar 2024 14:27:26 +0200 Subject: [PATCH 3/6] Test for fixed case --- .../Tests/Issues/IssueIsCrossRefTest.php | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/Propel/Tests/Issues/IssueIsCrossRefTest.php diff --git a/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php b/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php new file mode 100644 index 0000000000..e495303f87 --- /dev/null +++ b/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php @@ -0,0 +1,99 @@ + + + +
+ + +
+ + +
+ + +
+ + + + + + + + + + +
+ + + + + + + + + + +
+ +EOF; + QuickBuilder::buildSchema($schema); + } + } + + /** + * @return void + */ + public function testGenerateIsCrossRefCode() + { + $testGroupObject = new TestGroupObject(); + $testUserObject = new TestUserObject(); + $testGroupNegative = new TestGroupObjectNegative(); + $testUserNegative = new TestUserObjectNegative(); + + $this->assertTrue( + method_exists($testGroupObject, 'createTestUserObjectsQuery'), + 'Class does not have method createTestUserObjectsQuery' + ); + $this->assertTrue( + method_exists($testUserObject, 'createTestGroupObjectsQuery'), + 'Class does not have method createTestUserObjectsQuery' + ); + $this->assertTrue( + method_exists($testGroupNegative, 'createTestUserObjectNegativesQuery'), + 'Class does not have method createTestUserObjectsQuery' + ); + $this->assertTrue( + method_exists($testUserNegative, 'createTestGroupObjectNegativesQuery'), + 'Class does not have method createTestUserObjectsQuery' + ); + } +} From 0121b5475e4d90493d16ac02aaa13cb15f5d5776 Mon Sep 17 00:00:00 2001 From: vol4onok Date: Thu, 21 Mar 2024 14:35:20 +0200 Subject: [PATCH 4/6] Adjusted test --- tests/Propel/Tests/Issues/IssueIsCrossRefTest.php | 10 +++++----- .../Propel/Tests/Runtime/Connection/PropelPDOTest.php | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php b/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php index e495303f87..61ded4893d 100644 --- a/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php +++ b/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php @@ -19,7 +19,7 @@ * Regression test for https://github.com/propelorm/Propel2/pull/1994 * @group test1 */ -class IssuePr1994Test extends TestCase +class IssueIsCrossRefTest extends TestCase { /** * @return void @@ -54,8 +54,8 @@ public function setUp(): void - - + + @@ -87,11 +87,11 @@ public function testGenerateIsCrossRefCode() method_exists($testUserObject, 'createTestGroupObjectsQuery'), 'Class does not have method createTestUserObjectsQuery' ); - $this->assertTrue( + $this->assertFalse( method_exists($testGroupNegative, 'createTestUserObjectNegativesQuery'), 'Class does not have method createTestUserObjectsQuery' ); - $this->assertTrue( + $this->assertFalse( method_exists($testUserNegative, 'createTestGroupObjectNegativesQuery'), 'Class does not have method createTestUserObjectsQuery' ); diff --git a/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php b/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php index 4ec4ec52d3..8a6845cb74 100644 --- a/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php +++ b/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php @@ -11,6 +11,7 @@ use Exception; use Monolog\Handler\AbstractHandler; use Monolog\Logger; +use Monolog\LogRecord; use PDO; use PDOException; use Propel\Runtime\ActiveQuery\Criteria; @@ -564,7 +565,7 @@ class LastMessageHandler extends AbstractHandler * * @return bool */ - public function handle(array $record): bool + public function handle(LogRecord $record): bool { $this->latestMessage = (string)$record['message']; From 70d6b89bd05186a71702e134b548aab4a5701670 Mon Sep 17 00:00:00 2001 From: vol4onok Date: Thu, 21 Mar 2024 14:36:47 +0200 Subject: [PATCH 5/6] Reverted tem changes --- tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php b/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php index 8a6845cb74..4ec4ec52d3 100644 --- a/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php +++ b/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php @@ -11,7 +11,6 @@ use Exception; use Monolog\Handler\AbstractHandler; use Monolog\Logger; -use Monolog\LogRecord; use PDO; use PDOException; use Propel\Runtime\ActiveQuery\Criteria; @@ -565,7 +564,7 @@ class LastMessageHandler extends AbstractHandler * * @return bool */ - public function handle(LogRecord $record): bool + public function handle(array $record): bool { $this->latestMessage = (string)$record['message']; From 2f29c23134bae822414f04e38a99613e436cdb3a Mon Sep 17 00:00:00 2001 From: vol4onok Date: Fri, 29 Mar 2024 08:38:21 +0200 Subject: [PATCH 6/6] Cleanup --- tests/Propel/Tests/Issues/IssueIsCrossRefTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php b/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php index 61ded4893d..5e810d36e3 100644 --- a/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php +++ b/tests/Propel/Tests/Issues/IssueIsCrossRefTest.php @@ -17,7 +17,6 @@ /** * Regression test for https://github.com/propelorm/Propel2/pull/1994 - * @group test1 */ class IssueIsCrossRefTest extends TestCase {