webCOMAND

repo::new_collection()

Create a new collection associated with the repository.

Prototype

collection new_collection(mixed $array = [], array $options = [])

Parameters

  • array - Optional array or collection of objects to including in the new collection.  If an array of arrays/collections is provided, they will be merged into the new collection.
  • options - Associative array with zero or more of the following keys.
    • track_types - TRUE (default) to track content types in the collection.  FALSE to skip tracking types.
    • allow_duplicates - TRUE (default) if the array parameter contains the same object multiple times, include each instance in the collection.  FALSE will only include the first instance of each object.  This option only applies to this call.  Duplicate objects can still be added to the returned collection.

Return

A collection associated with the current repository.  It will be empty unless an optional array of objects is passed in.

Example

$contacts = $repo->new_collection();
$contacts[] = $repo->new_object('Contact');

Merge Example

$johns = $repo->get('FROM Presidents WHERE Name ILIKE '%John%');
$adams = $repo->get('FROM Presidents WHERE Name ILIKE '%Adams%');
$all_matches = $repo->new_collection(
    [$johns, $adams],
    ['allow_duplicates'=>FALSE]
);