Permalink
Browse files

Adding the ability to do a diff() of PropelCollections without strict…

… comparison flag
  • Loading branch information...
komapa committed Apr 9, 2012
1 parent f37ae58 commit c1c06f1a8fba5adce61f1fba691ab6b5933a94c4
Showing with 15 additions and 10 deletions.
  1. +2 −2 generator/lib/builder/om/PHP5ObjectBuilder.php
  2. +13 −8 runtime/lib/collection/PropelCollection.php
@@ -3594,7 +3594,7 @@ protected function addRefFKSet(&$script, $refFK)
*/
public function set{$relatedName}(PropelCollection \${$inputCollection}, PropelPDO \$con = null)
{
- \$this->{$inputCollection}ScheduledForDeletion = \$this->get{$relatedName}(new Criteria(), \$con)->diff(\${$inputCollection});
+ \$this->{$inputCollection}ScheduledForDeletion = \$this->get{$relatedName}(new Criteria(), \$con)->diff(\${$inputCollection}, false);
foreach (\${$inputCollection} as \${$inputCollectionEntry}) {
// Fix issue with collection modified by reference
@@ -3959,7 +3959,7 @@ public function set{$relatedName}(PropelCollection \${$inputCollection}, PropelP
->filterBy{$selfRelationName}(\$this)
->find(\$con);
- \$this->{$inputCollection}ScheduledForDeletion = \$this->get{$relCol}()->diff({$crossRefObjectClassName}s);
+ \$this->{$inputCollection}ScheduledForDeletion = \$this->get{$relCol}()->diff({$crossRefObjectClassName}s, false);
\$this->{$relColVarName} = {$crossRefObjectClassName}s;
foreach (\${$inputCollection} as \${$inputCollectionEntry}) {
@@ -303,39 +303,44 @@ public function clear()
/**
* Whether or not this collection contains a specified element
*
- * @param mixed $element
+ * @param mixed $element
+ * @param boolean $strict
+
* @return boolean
*/
- public function contains($element)
+ public function contains($element, $strict = true)
{
- return in_array($element, $this->getArrayCopy(), true);
+ return in_array($element, $this->getArrayCopy(), $strict);
}
/**
* Search an element in the collection
*
- * @param mixed $element
+ * @param mixed $element
+ * @param boolean $strict
+
* @return mixed Returns the key for the element if it is found in the collection, FALSE otherwise
*/
- public function search($element)
+ public function search($element, $strict = true)
{
- return array_search($element, $this->getArrayCopy(), true);
+ return array_search($element, $this->getArrayCopy(), $strict);
}
/**
* Returns an array of objects present in the collection that
* are not presents in the given collection.
*
* @param PropelCollection $collection A Propel collection.
+ * @param boolean $strict Whether to compare objects with the strict flag on/off
* @return PropelCollection An array of Propel objects from the collection that are not presents in the given collection.
*/
- public function diff(PropelCollection $collection)
+ public function diff(PropelCollection $collection, $strict = true)
{
$diff = clone $this;
$diff->clear();
foreach ($this as $object) {
- if (!$collection->contains($object)) {
+ if (!$collection->contains($object, $strict)) {
$diff[] = $object;
}
}

2 comments on commit c1c06f1

@VanTanev

This comment has been minimized.

Show comment Hide comment
@VanTanev

VanTanev Oct 5, 2012

This is now fixed in official propel: propelorm/Propel@945efa3

This is now fixed in official propel: propelorm/Propel@945efa3

@komapa

This comment has been minimized.

Show comment Hide comment
@komapa

komapa Oct 7, 2012

Create a new branch where you upgrade Propel to the latest version (from 2 months ago or later if we HAVE to). Make sure that everything works well and I will merge. I took 10 minutes to see what is involved but do not have the brainpower now to resolve the conflicts.

Create a new branch where you upgrade Propel to the latest version (from 2 months ago or later if we HAVE to). Make sure that everything works well and I will merge. I took 10 minutes to see what is involved but do not have the brainpower now to resolve the conflicts.

Please sign in to comment.