Skip to content

Commit 140f28e

Browse files
committed
Remove some overhead code
1 parent 959d761 commit 140f28e

File tree

2 files changed

+4
-41
lines changed

2 files changed

+4
-41
lines changed

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -215,48 +215,13 @@ public function getTable()
215215
public function getAttribute($key)
216216
{
217217
// Check if the key is an array dot notation.
218-
if (str_contains($key, '.') and array_has($this->attributes, $key)) {
218+
if ($key and str_contains($key, '.') and array_has($this->attributes, $key)) {
219219
return $this->getAttributeValue($key);
220220
}
221221

222-
$camelKey = camel_case($key);
223-
224-
// If the "attribute" exists as a method on the model, it may be an
225-
// embedded model. If so, we need to return the result before it
226-
// is handled by the parent method.
227-
if (method_exists($this, $camelKey)) {
228-
$method = new ReflectionMethod(get_called_class(), $camelKey);
229-
230-
// Ensure the method is not static to avoid conflicting with Eloquent methods.
231-
if (! $method->isStatic()) {
232-
$relations = $this->$camelKey();
233-
234-
// This attribute matches an embedsOne or embedsMany relation so we need
235-
// to return the relation results instead of the interal attributes.
236-
if ($relations instanceof EmbedsOneOrMany) {
237-
// If the key already exists in the relationships array, it just means the
238-
// relationship has already been loaded, so we'll just return it out of
239-
// here because there is no need to query within the relations twice.
240-
if (array_key_exists($key, $this->relations)) {
241-
return $this->relations[$key];
242-
}
243-
244-
// Get the relation results.
245-
return $this->getRelationshipFromMethod($key, $camelKey);
246-
}
247-
248-
if ($relations instanceof Relation) {
249-
// If the key already exists in the relationships array, it just means the
250-
// relationship has already been loaded, so we'll just return it out of
251-
// here because there is no need to query within the relations twice.
252-
if (array_key_exists($key, $this->relations) && $this->relations[$key] != null) {
253-
return $this->relations[$key];
254-
}
255-
256-
// Get the relation results.
257-
return $this->getRelationshipFromMethod($key, $camelKey);
258-
}
259-
}
222+
// This checks for embedded relation support.
223+
if (method_exists($this, $key) && ! method_exists(self::class, $key)) {
224+
return $this->getRelationValue($key);
260225
}
261226

262227
return parent::getAttribute($key);

src/Jenssegers/Mongodb/Relations/MorphTo.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ protected function getResultsByType($type)
3131

3232
$query = $instance->newQuery();
3333

34-
$query = $this->useWithTrashed($query);
35-
3634
return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
3735
}
3836
}

0 commit comments

Comments
 (0)