Skip to content

Commit

Permalink
Merge pull request #238 from art-institute-of-chicago/fix/patch-updat…
Browse files Browse the repository at this point in the history
…e-browser

Add patch to allow for updating morph browsers
  • Loading branch information
zachgarwood authored Dec 1, 2023
2 parents d25a313 + 4895c5c commit f34954a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"package": {
"type": "metapackage",
"name": "vendor/package-patches",
"version": "0.0.1",
"version": "0.0.2",
"require": {
"netresearch/composer-patches-plugin": "~1.2"
},
Expand All @@ -24,6 +24,10 @@
{
"title": "MA-129: Add limited formatting to CMS fields",
"url": "patches/MA-129---add-limited-formatting-to-cms-fields.diff"
},
{
"title": "MA-150: Allow updateBrowser() to handle morphOne relationships",
"url": "patches/MA-150---allow-update-browser-morphs.diff"
}
]
}
Expand All @@ -41,7 +45,7 @@
"laravel/tinker": "^2.8",
"league/fractal": "^0.16.0",
"michelf/php-smartypants": "^1.8",
"vendor/package-patches": "0.0.1"
"vendor/package-patches": "0.0.2"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand Down Expand Up @@ -95,6 +99,9 @@
},
"config": {
"optimize-autoloader": true,
"platform": {
"php": "8.1"
},
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
Expand Down
11 changes: 9 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions patches/MA-150---allow-update-browser-morphs.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/src/Repositories/Behaviors/HandleBrowsers.php b/src/Repositories/Behaviors/HandleBrowsers.php
index c84fbbbf..4ffecd79 100644
--- a/src/Repositories/Behaviors/HandleBrowsers.php
+++ b/src/Repositories/Behaviors/HandleBrowsers.php
@@ -5,8 +5,7 @@ namespace A17\Twill\Repositories\Behaviors;
use A17\Twill\Models\Behaviors\HasMedias;
use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
-use Illuminate\Database\Eloquent\Relations\HasMany;
-use Illuminate\Database\Eloquent\Relations\HasOne;
+use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
@@ -119,10 +118,7 @@ trait HandleBrowsers
}

$object->save();
- } elseif (
- $object->$relationship() instanceof HasOne ||
- $object->$relationship() instanceof HasMany
- ) {
+ } elseif ($object->$relationship() instanceof HasOneOrMany) {
$this->updateBelongsToInverseBrowser($object, $relationship, $relatedElements);
} else {
$object->$relationship()->sync($relatedElementsWithPosition);

0 comments on commit f34954a

Please sign in to comment.