Fix - Fix variant image duplication
Currently when adding images to a variant it's quite restrictive and doesn't reuse existing media records very well.
At the moment, when you add an image to the variant (even from choosing an existing product image) it will duplicate it, this isn't great as some variants will want to use the same image i.e. a generic green t-shirt across all sizes, causing the amount of media that gets added to the database and ultimately in storage to grow quickly.
This PR aims to solve that with these notable changes:
- Added a new link table
media_product_variantwith apositionpivot column - When adding new images to a variant directly, behind the scenes we will save these images against the product and populate the link table.
- When choosing an image that exists on the product, instead of duplicating it we simply add a row to the link table.
This then allows variants to have multiple images whilst still retaining them on the product, for use by other variants and also keeps the amount of files and media records being generated to a minimum.
- Removed the
mediarelation from theProductVariantin favour of animagesBelongsToManyrelationship.
The method getThumbnail() remains intact so has backwards compatibility in that respect.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated |
|---|---|---|---|
| getcandy-2-docs | ✅ Ready (Inspect) | Visit Preview | Sep 5, 2022 at 9:48AM (UTC) |