Delete product inverseAssociations#2280
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughUpdated ProductObserver::deleting to also delete inverseAssociations() during force deletes, executed after associations()->delete() and before channels()->detach(). No other functional branches or signatures changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/core/src/Observers/ProductObserver.php (3)
14-31: Consider wrapping the force-delete cascade in a DB transactionMultiple destructive operations are performed across relations. Wrapping them in a single transaction reduces the risk of partial cleanup if an intermediate query fails.
Example:
use Illuminate\Support\Facades\DB; public function deleting(ProductContract $product): void { if ($product->isForceDeleting()) { DB::transaction(function () use ($product) { $product->variants()->withTrashed()->get()->each->forceDelete(); $product->collections()->detach(); $product->customerGroups()->detach(); $product->urls()->delete(); $product->productOptions()->detach(); $product->associations()->delete(); $product->inverseAssociations()->delete(); $product->channels()->detach(); $product->tags()->detach(); }); } else { $product->variants()->get()->each->delete(); } }
15-15: Optional: avoid loading all variants in memory when force-deletingFor large catalogs, loading all variants to delete them may be memory-heavy. Chunking or cursor-based iteration reduces memory footprint.
Example with chunking:
$product->variants()->withTrashed()->chunkById(200, function ($variants) { $variants->each->forceDelete(); });
10-12: Docblock mismatch with method/eventThe docblock says “Handle the ProductVariant "deleted" event.” but the method is ProductObserver::deleting(ProductContract $product). Consider correcting to avoid confusion.
Suggested wording:
/** * Handle the Product "deleting" event. */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/core/src/Observers/ProductObserver.php(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/Observers/ProductObserver.php (1)
packages/core/src/Models/ProductVariant.php (1)
product(89-92)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
- GitHub Check: search - PHP 8.4 - L12.* ↑
- GitHub Check: core - PHP 8.4 - L12.* ↑ E
- GitHub Check: admin - PHP 8.4 - L12.* ↑ E
- GitHub Check: stripe - PHP 8.4 - L12.* ↑
- GitHub Check: stripe - PHP 8.4 - L12.* ↑ E
- GitHub Check: core - PHP 8.4 - L11.* ↑ E
- GitHub Check: stripe - PHP 8.3 - L12.* ↑
- GitHub Check: admin - PHP 8.4 - L11.* ↑ E
- GitHub Check: admin - PHP 8.4 - L11.* ↑
- GitHub Check: admin - PHP 8.3 - L12.* ↑ E
- GitHub Check: core - PHP 8.4 - L11.* ↑
- GitHub Check: core - PHP 8.3 - L12.* ↑
- GitHub Check: core - PHP 8.3 - L12.* ↑ E
- GitHub Check: admin - PHP 8.3 - L12.* ↑
- GitHub Check: admin - PHP 8.3 - L11.* ↑
- GitHub Check: admin - PHP 8.3 - L11.* ↑ E
- GitHub Check: core - PHP 8.3 - L11.* ↑
- GitHub Check: core - PHP 8.3 - L11.* ↑ E
🔇 Additional comments (1)
packages/core/src/Observers/ProductObserver.php (1)
27-28: Verified hard-delete semantics for ProductAssociation
The ProductAssociation model does not use SoftDeletes, so associations()->delete() and inverseAssociations()->delete() already perform permanent deletes. No forceDelete() changes are needed.
Summary by CodeRabbit