Skip to content

Instantly share code, notes, and snippets.

@intel352
Created March 13, 2012 15:07
Show Gist options
  • Save intel352/2029327 to your computer and use it in GitHub Desktop.
Save intel352/2029327 to your computer and use it in GitHub Desktop.
Suggest solution to search an object's array in Riak, using ActiveDocument + js map function
<?php
use \ext\activedocument\Criteria;
$criteria = new Criteria;
$criteria->addColumnCondition(array('slug'=>$slug));
$category = Category::model()->find($criteria);
$criteria = new Criteria;
$criteria->order='updated ASC';
$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'=>$category->primaryKey)));
$apps = App::model()->findAll($criteria);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment