Skip to content

Instantly share code, notes, and snippets.

@biakaveron
Created August 27, 2010 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biakaveron/553008 to your computer and use it in GitHub Desktop.
Save biakaveron/553008 to your computer and use it in GitHub Desktop.
how to delete all user roles? Need ORM changes
/**
* Removes a relationship between this model and another (or delete all relationships).
*
* @param string alias of the has_many "through" relationship
* @param mixed related ORM model or NULL to clear relationship
* @return ORM
*/
public function remove($alias, ORM $model = NULL)
{
$query = DB::delete($this->_has_many[$alias]['through'])
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk());
if ( ! is_null($model))
{
// delete $model only
$query->where($this->_has_many[$alias]['far_key'], '=', $model->pk());
}
$query->execute($this->_db);
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment