Created
March 13, 2012 15:07
-
-
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
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, 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