Permalink
Browse files

Changed meaning of & in preload.

  • Loading branch information...
1 parent 81dccd5 commit e30eec8106c6ba1ee85247e36177d714b536e9b7 @gabordemooij committed Dec 1, 2012
Showing with 5 additions and 6 deletions.
  1. +4 −5 RedBean/OODB.php
  2. +1 −1 testing/RedUNIT/Base/Preloading.php
View
@@ -908,14 +908,13 @@ public function setDepList($dep) {
*/
public function preload($beans, $types, $closure = null) {
if (is_string($types)) $types = explode(',',$types);
- $oldFields = array(); $i=0; $retrievals = array();
+ $oldFields = array(); $i=0; $retrievals = array(); $oldField = '';
foreach($types as $key => $type) {
$retrievals[$i] = array();
$map = $ids = array();
$field = (is_numeric($key)) ? $type : $key;//use an alias?
- $addToStack = true;
- if (strpos($field,'*')!==false) { $field = str_replace('*',implode('.',$oldFields),$field); $addToStack = true; }
- if (strpos($field,'&')!==false) { $field = str_replace('&',implode('.',$oldFields),$field); $addToStack = false; }
+ if (strpos($field,'*')!==false) { $oldFields[]= $oldField; $field = str_replace('*',implode('.',$oldFields),$field);}
+ if (strpos($field,'&')!==false) { $field = str_replace('&',implode('.',$oldFields),$field);}
$filteredBeans = $beans;
while($p = strpos($field,'.')) { //filtering: find the right beans in the path
$nesting = substr($field,0,$p);
@@ -930,8 +929,8 @@ public function preload($beans, $types, $closure = null) {
$filteredBeans = $filtered;
$field = substr($field,$p+1);
}
+ $oldField = $field;
if (strpos($type,'.')) $type = $field;
- if ($addToStack) $oldFields[]= $field;
foreach($filteredBeans as $bean) { //gather ids to load the desired bean collections
if (strpos($field,'own')===0) { //based on bean->id for ownlist
$id = $bean->id; $ids[$id] = $id;
@@ -301,7 +301,7 @@ public function run() {
R::storeAll($authors);
$texts = R::find('text');
$hasNuked = false;
- R::preload($texts,'page,*.book,&.author,*.shelf',function($text,$page,$book,$author,$shelf){
+ R::preload($texts,'page,*.book,*.author,&.shelf',function($text,$page,$book,$author,$shelf){
global $hasNuked;
if (!$hasNuked) { R::nuke(); $hasNuked = true; }
asrt($text->getMeta('type'),'text');

0 comments on commit e30eec8

Please sign in to comment.