You will need to extend the EntityAPIController in your entity. Here is an example of my hook_entity_info and then the method that handles deletion of of your entity:
/**
* Implements hook_entity_info()
*
* @return array
*/
function iplist_entity_info() {
$info = array();
$info['iplist'] = array(
'label' => t('IP Address List'),
'base table' => 'iplistentity_iplist',
'entity keys' => array(
'id' => 'id',
'label' => 'name',
),
'uri callback' => 'entity_class_uri',
'entity class' => 'IpListEntity',
'controller class' => 'IpListEntityController',
'admin ui' => array(
'path' => 'admin/iplist',
'controller class' => 'IpListEntityUIController',
'menu wildcard' => '%iplist',
'file' => 'iplist.admin.inc',
),
'module' => 'iplist',
'access callback' => 'iplist_access_callback',
'fieldable' => TRUE,
'bundles' => array(
'iplist' => array(
'label' => t('IP Address List'),
'admin' => array(
'path' => 'admin/iplist',
'access arguments' => array('administer iplists'),
),
),
),
'views controller class' => 'EntityDefaultViewsController',
);
return $info;
}
class IpListEntityController extends EntityAPIController {
/**
* IP list save
*
* @param $entity
* @param DatabaseTransaction $transaction
* @return bool|int
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
if (isset($entity->is_new)) {
$entity->created_at = REQUEST_TIME;
}
$entity->updated_at = REQUEST_TIME;
return parent::save($entity, $transaction);
}
/**
* IPList delete controller
*
* @param $ids
* @param DatabaseTransaction $transaction
*/
public function delete($ids, DatabaseTransaction $transaction = NULL) {
$entities = $ids ? $this->load($ids) : FALSE;
if (!$entities) {
// Do nothing, in case invalid or no ids have been passed.
return;
}
$iplist_single = array_pop($entities);
$iplistentity = self::loadByEntityWrapper($iplist_single);
$iterator = $iplistentity->field_ip_address->value();
foreach($iterator as $ip)
{
IpEntityController::deleteByWrapper($ip);
}
return parent::delete($ids, $transaction);
}
}