Skip to content

Instantly share code, notes, and snippets.

@intel352
Created April 2, 2012 14:56
Show Gist options
  • Save intel352/2284132 to your computer and use it in GitHub Desktop.
Save intel352/2284132 to your computer and use it in GitHub Desktop.
Remove from relation range and search
<?php
$criteria = new \ext\activedocument\Criteria;
$criteria->addMapPhase('
function(value, keyData, arg) {
if(!value["not_found"]) {
var object = Riak.mapValuesJson(value)[0];
if(object.hasOwnProperty(arg.col) && object[arg.col] instanceof Array) {
if(object[arg.col].indexOf(arg.val) != -1)
return [[value.bucket,value.key]];
}
}
return [];
}
', array('arg' => array('col'=>'categories','val'=>$this->primaryKey)));
$apps = App::model()->findAll($criteria);
echo count($apps) // output 0
<?php
$app = App::model()->findByPk('4ZHbpAFMllOcBG4tQlA4XTaO18Q');
$category = Category::model()->findByPk('LUWpN70YaT8HxYBVZtZZrUmfx0R');
$app->removeRelation($category, 'categories');
$app->save(false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment