From 0598f111e40348b07ca4466fa88693a6880c5964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cho=C5=82aj?= Date: Fri, 26 Jul 2024 08:19:19 +0200 Subject: [PATCH] Fix migration --- app/Models/Product.php | 19 +++++++++++++++++++ ...column_to_options_schemas_and_products.php | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index 2cd9a1fc4..35d2f3089 100755 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -224,6 +224,25 @@ public function schemas(): HasMany ->with(['options', 'metadata', 'metadataPrivate', 'options.metadata', 'options.metadataPrivate']); } + /** + * @deprecated + */ + public function oldRequiredSchemas(): BelongsToMany + { + return $this->oldSchemas()->where('required', true); + } + + /** + * @deprecated + */ + public function oldSchemas(): BelongsToMany + { + return $this + ->belongsToMany(Schema::class, 'product_schemas') + ->with(['options', 'metadata', 'metadataPrivate', 'options.metadata', 'options.metadataPrivate']) + ->orderByPivot('order'); + } + public function scopePublic(Builder $query): Builder { return $query->where('public', true); diff --git a/database/migrations/2022_03_01_073057_add_available_column_to_options_schemas_and_products.php b/database/migrations/2022_03_01_073057_add_available_column_to_options_schemas_and_products.php index 7322bae68..5344f4bed 100755 --- a/database/migrations/2022_03_01_073057_add_available_column_to_options_schemas_and_products.php +++ b/database/migrations/2022_03_01_073057_add_available_column_to_options_schemas_and_products.php @@ -25,7 +25,7 @@ public function up(): void // $items = Item::all(); // $items->each(fn ($item) => $availabilityService->calculateAvailabilityOnAllItemRelations($item)); - $products = Product::doesntHave('schemas')->get(); + $products = Product::doesntHave('oldSchemas')->get(); $products->each(function (Product $product): void { $product->update(['available' => true]); });