Created
August 27, 2010 07:52
-
-
Save biakaveron/553008 to your computer and use it in GitHub Desktop.
how to delete all user roles? Need ORM changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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