]> BookStack Code Mirror - bookstack/blobdiff - app/References/ReferenceFetcher.php
Images: Added nulling of image page relation on page delete
[bookstack] / app / References / ReferenceFetcher.php
index 0d9883a3edcbcc057136a3273cd5433055286f55..8588c6e2c8ef3ab16dd8464f36dc42e44957f42d 100644 (file)
@@ -20,10 +20,10 @@ class ReferenceFetcher
      * Query and return the references pointing to the given entity.
      * Loads the commonly required relations while taking permissions into account.
      */
-    public function getReferencesToEntity(Entity $entity): Collection
+    public function getReferencesToEntity(Entity $entity, bool $withContents = false): Collection
     {
         $references = $this->queryReferencesToEntity($entity)->get();
-        $this->mixedEntityListLoader->loadIntoRelations($references->all(), 'from');
+        $this->mixedEntityListLoader->loadIntoRelations($references->all(), 'from', false, $withContents);
 
         return $references;
     }
@@ -41,7 +41,8 @@ class ReferenceFetcher
     {
         $baseQuery = Reference::query()
             ->where('to_type', '=', $entity->getMorphClass())
-            ->where('to_id', '=', $entity->id);
+            ->where('to_id', '=', $entity->id)
+            ->whereHas('from');
 
         return $this->permissions->restrictEntityRelationQuery(
             $baseQuery,