webCOMAND

collection::remove_object()

Remove a specific object, or object at a specific offset from the collection.  To remove a specific object, pass the object itself.  To remove an object at a specific offset, pass the offset.

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

As an alternative to passing in an offset, use unset($collection[3]).  To remove a set of objects, use remove_objects().

Prototype

array remove_object(mixed $object_or_offset)

Parameters

  • object_or_offset - An Object to remove, or index of the object in the collection to remove.

Return

Returns an associative array with one item that represents the removed object where the key is the index of the removed object and the value is the object itself.

Example

// Remove the first relative from all contact's Relatives field.
$contacts = $repo->get("FROM Contact WHERE !ISNULL(Relatives)");
foreach($contacts as $contact) {
    $contact->Relatives->remove_object(0);
    $contact->approve();
}

Related

clear_objects(), remove_objects()