webCOMAND

collection::remove_objects()

Remove specific objects from the collection, by object or offset.

If the collection represents an object field, and the object is subsequently stored, saved or approved, the objects will be eliminated from the field.  If the object field contains embedded object, the objects themselves will also be removed.  If the object field references the objects, then the objects will only be removed from the field, and not removed from the repository.

To remove all objects from the collection, use clear_objects().

Prototype

array remove_objects(mixed $objects)

Parameters

  • objects - Collection or array of objects to remove from the current collection.  An array of integer offsets can also be passed in to remove objects at specific indexes.

Return

Returns an associative array of the removed objects where the key is the index of the removed object, before objects were removed, and the value is the corresponding object.

Example

// Remove contacts whose name starts with J from all contact's Relatives field.
$j_contacts = $repo->get("FROM Contact WHERE Name ILIKE 'j%'");
$all_contacts = $repo->get("FROM Contact WHERE !ISNULL(Relatives)");
foreach($all_contacts as $contact) {
    $contact->Relatives->remove_objects($j_contacts);
    $contact->approve();
}

Related

collection::clear_objects(), collection::remove_object()