Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 0324860

Browse files
author
Nik Barham
committed
Fixed a "bug" where a grouped ->$var 1-M property call did not store the returned objects in the $obj->_data->externals[$var] arrays
1 parent 12825b1 commit 0324860

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/Automatorm/Orm/Data.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,27 @@ public static function groupJoin(Collection $collection, $var, $where = [])
138138
// Remove duplicates from the group
139139
$ids = array_unique($collection->{$var . '_id'}->toArray());
140140

141-
/* Call Tablename::factory(foreign key id) to get the object we want */
141+
/* Call Tablename::factoryObjectCache(foreign key ids) to makes sure all the objects we want are in the instance cache */
142142
$table = $proto->model['many-to-one'][$var];
143-
$results = Model::factoryObjectCache($ids, $table, $proto->database);
144-
145-
return $results;
143+
144+
if (!$where)
145+
{
146+
$results = Model::factoryObjectCache($ids, $table, $proto->database);
147+
148+
// Store the object results on the relevant objects
149+
foreach ($collection as $obj)
150+
{
151+
$obj->_data->external[$var] = Model::factoryObjectCache($obj->{$var . '_id'}, $table, $proto->database);
152+
}
153+
154+
return $results;
155+
}
156+
else
157+
{
158+
$results = Model::factory($where + ['id' => $ids], $table, $proto->database);
159+
160+
return $results;
161+
}
146162
}
147163

148164
/* Look for lists of objects in other tables referencing this one */

0 commit comments

Comments
 (0)