Created
March 7, 2012 18:49
-
-
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
This file contains hidden or 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
<?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