From d665bccaa9ea9af94342a4fa96be545dc1dcd571 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 16 Nov 2010 18:03:03 -0200 Subject: Trying to avoid duplicate entries at addManyToManyEntities() --- lib/sfIsisImporterRelations.class.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/sfIsisImporterRelations.class.php') diff --git a/lib/sfIsisImporterRelations.class.php b/lib/sfIsisImporterRelations.class.php index bf41120..248bf99 100644 --- a/lib/sfIsisImporterRelations.class.php +++ b/lib/sfIsisImporterRelations.class.php @@ -151,9 +151,19 @@ class sfIsisImporterRelations extends sfIsisImporterEntities { */ public function addManyToManyEntities(&$model, array $values, $relation, $key = 'name') { + $existing = array(); + foreach ($values as $value) { - $this->addManyToMany($model, $value, $relation, $key); + // Prevent duplicate entries. + if (!in_array($value, $existing)) + { + $existing[] = $value; + $this->addManyToMany($model, $value, $relation, $key); + } + else { + $this->log("Found duplicate entry $value for relation $key.", 'debug'); + } } } -- cgit v1.2.3