Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added SQL-with in Preload

  • Loading branch information...
commit 47065b84c57daaf315bd02e77beaa42b490da3a1 1 parent 09587b6
@gabordemooij authored
View
4 RedBean/Facade.php
@@ -3,7 +3,7 @@
* RedBean Facade
*
* Version Information
- * RedBean Version @version 3.4
+ * RedBean Version @version 3.4.1
*
* @file RedBean/Facade.php
* @desc Convenience class for RedBeanPHP.
@@ -80,7 +80,7 @@ class RedBean_Facade {
* @return string
*/
public static function getVersion() {
- return '3.4';
+ return '3.4.1';
}
/**
* Kickstarts redbean for you. This method should be called before you start using
View
7 RedBean/OODB.php
@@ -822,7 +822,8 @@ public function setDepList($dep) {
public function preload($beans, $types, $closure = null) {
if (is_string($types)) $types = explode(',', $types);
$oldFields = array(); $i = 0; $retrievals = array(); $oldField = '';
- foreach($types as $key => $type) {
+ foreach($types as $key => $typeInfo) {
+ list($type,$sqlObj) = (is_array($typeInfo) ? $typeInfo : array($typeInfo, null));
$map = $ids = $retrievals[$i] = array();
$field = (is_numeric($key)) ? $type : $key;//use an alias?
if (strpos($field, '*') !== false) {
@@ -891,7 +892,7 @@ public function preload($beans, $types, $closure = null) {
$linked[$linkID][] = $linkBean;
$targetIDs[$linkBean->$targetIDField] = $linkBean->$targetIDField;
}
- $sharedBeans = $this->batch($type, $targetIDs);
+ $sharedBeans = $this->find($type, array('id' => $targetIDs), $sqlObj, (!is_null($sqlObj)));
foreach($filteredBeans as $filteredBean) {
$list = array();
if (isset($linked[$filteredBean->id])) {
@@ -910,7 +911,7 @@ public function preload($beans, $types, $closure = null) {
}
} elseif (strpos($field, 'own') === 0) {//preload for own-list using find
$link = $bean->getMeta('type').'_id';
- $children = $this->find($type, array($link => $ids));
+ $children = $this->find($type, array($link => $ids), $sqlObj, (!is_null($sqlObj)));
foreach($filteredBeans as $filteredBean) {
$list = array();
foreach($children as $child) if ($child->$link == $filteredBean->id) $list[$child->id] = $child;
View
35 testing/RedUNIT/Base/Preloading.php
@@ -595,6 +595,27 @@ function($t,$p,$x,$b,$c,$a)use(&$hasNuked,&$i){
R::nuke();
R::$writer->setUseCache(false);
+ $books = R::dispense('book',4);
+ foreach($books as $b) $b->ownPage = R::dispense('page',2);
+ foreach($books as $b) $b->sharedAd = R::dispense('ad',2);
+ R::storeAll($books);
+ $books = R::find('book');
+ R::preload($books,array(
+ 'ownPage' => array('page',array(' AND id > 0 LIMIT ? ', array(2))),
+ 'sharedAd' => array('ad',array(' AND id > 0 LIMIT ? ',array(4)))
+ )
+ );
+ asrt(count($books[1]->ownPage),2);
+ asrt(count($books[1]->sharedAd),2);
+ asrt(count($books[2]->ownPage),0);
+ asrt(count($books[2]->sharedAd),2);
+ asrt(count($books[3]->ownPage),0);
+ asrt(count($books[3]->sharedAd),0);
+
+
+
+ R::nuke();
+ R::$writer->setUseCache(false);
$villages = R::dispense('village',3);
foreach($villages as $v) $v->ownBuilding = R::dispense('building',3);
@@ -626,7 +647,11 @@ function($t,$p,$x,$b,$c,$a)use(&$hasNuked,&$i){
R::storeAll($villages);
$towns = R::find('village');
$counter = 0;
- R::each($towns,array('sharedArmy'=>'army','sharedArmy.sharedSoldier'=>'soldier','ownBuilding'=>'building','ownBuilding.ownBook'=>'book','world'),function($t,$a,$s,$b,$x,$w) use(&$counter) {
+ R::each($towns,array(
+ 'sharedArmy'=>'army',
+ 'sharedArmy.sharedSoldier' => array('soldier', array(' ORDER BY name DESC ',array())),
+ 'ownBuilding'=> array('building', array(' ORDER BY name DESC ',array())),
+ 'ownBuilding.ownBook'=>'book','world'),function($t,$a,$s,$b,$x,$w) use(&$counter) {
if ($counter === 0) {
asrt($w,null);
asrt((string)$t->name,'0');
@@ -635,8 +660,7 @@ function($t,$p,$x,$b,$c,$a)use(&$hasNuked,&$i){
sort($list);
asrt(implode(',',$list),'1,2');
$list = array(); foreach($s as $item) $list[] = $item->name;
- sort($list);
- asrt(implode(',',$list),'1,2');
+ asrt(implode(',',$list),'2,1');
$list = array(); foreach($b as $item) $list[] = $item->name;
sort($list);
asrt(implode(',',$list),'0');
@@ -666,8 +690,7 @@ function($t,$p,$x,$b,$c,$a)use(&$hasNuked,&$i){
sort($list);
asrt(implode(',',$list),'0,1,2');
$list = array(); foreach($b as $item) $list[] = $item->name;
- sort($list);
- asrt(implode(',',$list),'1,2');
+ asrt(implode(',',$list),'2,1');
$list = array(); foreach($x as $item) $list[] = $item->name;
sort($list);
asrt(implode(',',$list),'2,3,4');
@@ -706,5 +729,5 @@ function($t,$p,$x,$b,$c,$a)use(&$hasNuked,&$i){
$counter++;
});
- }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.