11.3.3 CRUD operations: DELETE
Repository->delete()
The delete() API:
/**
* Delete Entity from DB
* @param mixed $EntityOrKey object or its primary keys
* @param int $fetchMode fetch mode (FETCH_OBJ, FETCH_ARRAY, FETCH_RAW), FALSE to skip fetch before delete
* @param string|null $fetchSubset optional fetch subset as defined in @orm-subset
* @return mixed $Entity object or array if $fetchMode, TRUE if not $fetchMode, FALSE on failure
* @throws Exception
*/
function delete($EntityOrKey, $fetchMode=self::FETCH_OBJ, $fetchSubset=null)
Example:
// by primary key
$UserRepository->delete(34);
// by object
$User = $UserRepository->fetch(34);
$UserRepository->delete($User);
Repository->deleteAll()
API:
/**
* Fetch an Entity by a set of Criteria and ORDER BY
* @param integer $limit LIMIT
* @param string|null $orderExp ORDER BY expression
* @param string|null $criteriaExp CRITERIA expression
* @return integer n° of deleted entities
*/
function deleteAll($limit, $orderExp=null, $criteriaExp=null)
Example:
$UsersRepository->deleteAll(3, 'age.ASC', 'age,GT,21');
Updated about 1 month ago