|
6 | 6 |
|
7 | 7 | trait BuilderTrait |
8 | 8 | { |
| 9 | + /** |
| 10 | + * Get the hydrated models without eager loading. |
| 11 | + * |
| 12 | + * @param array $columns |
| 13 | + * @return \Illuminate\Database\Eloquent\Model[] |
| 14 | + */ |
| 15 | + public function getModels($columns = array('*')) |
| 16 | + { |
| 17 | + // make sure that we select the version table, if the main table is selected |
| 18 | + $tempColumns = isset($this->query->columns) |
| 19 | + ? array_merge($columns, $this->query->columns) |
| 20 | + : $columns; |
| 21 | + foreach($tempColumns as $column) { |
| 22 | + $segments = explode('.', $column); |
| 23 | + if ($segments[0] == $this->model->getTable()) { |
| 24 | + $this->query->addSelect($this->model->getVersionTable().'.*'); |
| 25 | + break; |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + return parent::getModels($columns); |
| 30 | + } |
| 31 | + |
9 | 32 | /** |
10 | 33 | * Insert a new record into the database. |
11 | 34 | * |
@@ -227,18 +250,18 @@ protected function getVersionValues(array $values) |
227 | 250 | */ |
228 | 251 | protected function isVersionedKey($key, array $versionedKeys) |
229 | 252 | { |
230 | | - $keyFractions = explode(".",$key); |
| 253 | + $segments = explode(".",$key); |
231 | 254 |
|
232 | | - if (count($keyFractions) > 2) { |
| 255 | + if (count($segments) > 2) { |
233 | 256 | throw new Exception("Key '".$key."' has too many fractions."); |
234 | 257 | } |
235 | 258 |
|
236 | | - if (count($keyFractions) == 1 && in_array($keyFractions[0], $versionedKeys)) { |
237 | | - return $keyFractions[0]; |
| 259 | + if (count($segments) == 1 && in_array($segments[0], $versionedKeys)) { |
| 260 | + return $segments[0]; |
238 | 261 | } |
239 | 262 |
|
240 | | - if (count($keyFractions) == 2 && $keyFractions[0] == $this->model->getVersionTable() && in_array($keyFractions[1], $versionedKeys)) { |
241 | | - return $keyFractions[1]; |
| 263 | + if (count($segments) == 2 && $segments[0] == $this->model->getVersionTable() && in_array($segments[1], $versionedKeys)) { |
| 264 | + return $segments[1]; |
242 | 265 | } |
243 | 266 |
|
244 | 267 | return null; |
|
0 commit comments