$hydrated = [];
foreach ($this->entities as $entity) {
- $data = $entity->toArray();
+ $data = $entity->getRawOriginal();
$instance = Entity::instanceFromType($entity->type);
if ($instance instanceof Page) {
unset($data['description']);
}
- $instance->forceFill($data);
+ $instance = $instance->setRawAttributes($data, true);
$hydrated[] = $instance;
}
}
});
- $parents = $filtered ? (new EntityHydrator($parentQuery->get()->all()))->hydrate() : [];
+ $parentModels = $filtered ? $parentQuery->get()->all() : [];
+ $parents = (new EntityHydrator($parentModels))->hydrate();
$parentMap = [];
foreach ($parents as $parent) {
$parentMap[$parent->type . ':' . $parent->id] = $parent;
foreach ($entities as $entity) {
if ($entity instanceof Page || $entity instanceof Chapter) {
- $key = 'book:' . $entity->getAttribute('book_id');
- $entity->setRelation('book', $parentMap[$key] ?? null);
+ $key = 'book:' . $entity->getRawAttribute('book_id');
+ $entity->setAttribute('book', $parentMap[$key] ?? null);
}
if ($entity instanceof Page) {
- $key = 'chapter:' . $entity->getAttribute('chapter_id');
- $entity->setRelation('chapter', $parentMap[$key] ?? null);
+ $key = 'chapter:' . $entity->getRawAttribute('chapter_id');
+ $entity->setAttribute('chapter', $parentMap[$key] ?? null);
}
}
}
protected function getPageOfDataFromQuery(EloquentBuilder $query, int $page, int $count): Collection
{
$entities = $query->clone()
-// ->with(array_filter($relations))
->skip(($page - 1) * $count)
->take($count)
->get();
$hydrated = (new EntityHydrator($entities->all(), true, true))->hydrate();
- // TODO - Load in books for pages/chapters efficiently (scoped to visible)
- // TODO - Load in chapters for pages efficiently (scoped to visible)
- // TODO - Load in tags efficiently
-
return collect($hydrated);
}