Skip to content

Instantly share code, notes, and snippets.

@intel352
Created March 7, 2012 18:49
Show Gist options
  • Save intel352/1995082 to your computer and use it in GitHub Desktop.
Save intel352/1995082 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,args) {
if(!value["not_found"]) {
var object = Riak.mapValuesJson(value)[0];
if(object.hasOwnProperty(args.col) && object[args.col] instanceof Array) {
if(args.val in object[args.col])
return [[value.bucket,value.key]];
}
}
return [];
}
', 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