- ⌂ collection
- Methods
Constructor
Create a new collection.
A collection is more typically created with repository::new_collection().
Prototype
collection __construct(repository $repo, mixed $array = [], bool $track_types = TRUE)
Parameters
- repo - The repository that will be used by the collection and to save objects in the collection. Objects added to the collection may still be associated with another repository.
- array - Optional object, or array/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), information about the types of objects will be tracked for efficient retrieval, including the number of objects of each type. If FALSE, type information will not be tracked, which can help improve performance when not needed.
- 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.
Example
$object = $repo->get_first('FROM Contact');
// collection a will contain just $object
$a = new \comand\repository\collection($repo, $object);
// collection b will contain just $object
$b = new \comand\repository\collection($repo, $a);
// collection c will contain $object twice
$c = new \comand\repository\collection($repo, [$a, $b]);
// collection d will contain just $object
$d = new \comand\repository\collection(
$repo,
[$a, $b],
['allow_duplicates'=>FALSE]
);