File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
src/Database/Eloquent/Relations Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -38,4 +38,30 @@ public function addEagerConstraints(array $models)
3838
3939 $ this ->query ->{$ whereIn }($ key , $ this ->getEagerModelKeys ($ models ));
4040 }
41+
42+ /**
43+ * Gather the keys from an array of related models.
44+ *
45+ * @param array $models
46+ * @return array
47+ */
48+ protected function getEagerModelKeys (array $ models )
49+ {
50+ $ keys = [];
51+
52+ // First we need to gather all of the keys from the parent models so we know what
53+ // to query for via the eager loading query. We will add them to an array then
54+ // execute a "where in" statement to gather up all of those related records.
55+ // Unlike other DB Engines FM does not support nulls and uses an empty string instead.
56+ foreach ($ models as $ model ) {
57+ $ value = $ model ->{$ this ->foreignKey };
58+ if (! is_null ($ value ) && $ value !== '' ) {
59+ $ keys [] = $ value ;
60+ }
61+ }
62+
63+ sort ($ keys );
64+
65+ return array_values (array_unique ($ keys ));
66+ }
4167}
You can’t perform that action at this time.
0 commit comments