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

Significant performance improvement by bypassing Eloquent model magic #97

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Support/RelationBuilder.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public function build(Entity $entity): void
foreach ($attributes as $attribute) {
$relation = $this->getRelationClosure($entity, $attribute);

$entity->setEntityAttributeRelation($attribute->getAttribute('slug'), $relation);
$entity->setEntityAttributeRelation((string) ($attribute->getAttributes()['slug'] ?? null), $relation);
}
}

@@ -41,7 +41,7 @@ public function build(Entity $entity): void
*/
protected function getRelationClosure(Entity $entity, Attribute $attribute): Closure
{
$method = $attribute->is_collection ? 'hasMany' : 'hasOne';
$method = (bool) ($attribute->getAttributes()['is_collection'] ?? null) ? 'hasMany' : 'hasOne';

// This will return a closure fully binded to the current entity instance,
// which will help us to simulate any relation as if it was made in the