Spot\Entity\Collection::merge PHP Method

merge() public method

Merge another collection into this collections set of entities This will only add entitys that don't already exist in the current collection
public merge ( Collection $collection, $onlyUnique = true )
$collection Collection
    public function merge(\Spot\Entity\Collection $collection, $onlyUnique = true)
    {
        foreach ($collection as $entity) {
            if ($onlyUnique && in_array($entity, $this->_results)) {
                continue;
                // Skip - entity already exists in collection
            }
            $this->add($entity);
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testMergeIsNotUnique()
 {
     $collection2 = new \Spot\Entity\Collection();
     $this->collection->add(new Entity_Post(array('foo' => 'bar')));
     $collection2->add(new Entity_Post(array('foo' => 'bar')));
     $collection2->add(new Entity_Post());
     $collection2->merge($this->collection, false);
     $this->assertEquals(3, count($collection2));
 }