From 5a77f9e31d065a79985fe903daed84e5ede20a73 Mon Sep 17 00:00:00 2001 From: ppatrik <8960712+ppatrik@users.noreply.github.com> Date: Wed, 27 Jun 2018 18:35:38 +0200 Subject: [PATCH 1/2] Archivable behaviour with FK customization. (#1) * Archivable behaviour with FK customization. Added two boolan parameters: * archive_foreign_keys (default: false) - on true FK will be copied to Archive table class, so API for archive and non-archive class is the same. * archive_foreign_keys_skip_sql (default: true) - same API is enought so database FK will be skiped by default. * Fixed parameter checks. --- .../Behavior/Archivable/ArchivableBehavior.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Propel/Generator/Behavior/Archivable/ArchivableBehavior.php b/src/Propel/Generator/Behavior/Archivable/ArchivableBehavior.php index a3bbeec2c8..638fc20a6f 100644 --- a/src/Propel/Generator/Behavior/Archivable/ArchivableBehavior.php +++ b/src/Propel/Generator/Behavior/Archivable/ArchivableBehavior.php @@ -28,6 +28,8 @@ class ArchivableBehavior extends Behavior 'archive_table' => '', 'archive_phpname' => null, 'archive_class' => '', + 'archive_foreign_keys' => 'false', + 'archive_foreign_keys_skip_sql' => 'true', 'log_archived_at' => 'true', 'archived_at_column' => 'archived_at', 'archive_on_insert' => 'false', @@ -99,7 +101,15 @@ protected function addArchiveTable() 'type' => 'TIMESTAMP' ]); } - // do not copy foreign keys + // copy foreign keys if enabled in parameters + if ($this->getParameter('archive_foreign_keys') == 'true') { + foreach ($table->getForeignKeys() as $foreignKey) { + $copiedForeignKey = clone $foreignKey; + // database foreing keys are not required + $copiedForeignKey->setSkipSql($this->getParameter('archive_foreign_keys_skip_sql') == 'true'); + $archiveTable->addForeignKey($copiedForeignKey); + } + } // copy the indices foreach ($table->getIndices() as $index) { $copiedIndex = clone $index; From b379b7bbbef862c9aeeb046fa8a9071328646f6c Mon Sep 17 00:00:00 2001 From: ppatrik <8960712+ppatrik@users.noreply.github.com> Date: Wed, 27 Jun 2018 18:42:13 +0200 Subject: [PATCH 2/2] After adding related objects as collection. Property modifiedColumns is changed after adding/changing related objects. --- src/Propel/Generator/Builder/Om/ObjectBuilder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Propel/Generator/Builder/Om/ObjectBuilder.php b/src/Propel/Generator/Builder/Om/ObjectBuilder.php index 23f73cb27c..8a79da3457 100644 --- a/src/Propel/Generator/Builder/Om/ObjectBuilder.php +++ b/src/Propel/Generator/Builder/Om/ObjectBuilder.php @@ -4258,6 +4258,8 @@ public function set{$relatedName}(Collection \${$inputCollection}, ConnectionInt \$this->{$collName} = \${$inputCollection}; \$this->{$collName}Partial = false; + \$this->modifiedColumns[\"{$collName}\"] = true; + return \$this; } ";