| @@ -31,9 +31,26 @@ | ||
| 31 | 31 | { |
| 32 | 32 | return $this->belongsTo(AttributeTerm::class, 'term_id', 'id'); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | + public function variation() | |
| 36 | + { | |
| 37 | + return $this->belongsTo(ProductVariation::class, 'object_id', 'id'); | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * The ProductDetail of the product this link's variation belongs to. | |
| 42 | + * object_id holds a ProductVariation id, never a ProductDetail id, so the | |
| 43 | + * detail is resolved through the variation's post_id. | |
| 44 | + */ | |
| 35 | 45 | public function productDetails() |
| 36 | 46 | { |
| 37 | - return $this->belongsTo(ProductDetail::class, 'object_id', 'id'); | |
| 47 | + return $this->hasOneThrough( | |
| 48 | + ProductDetail::class, | |
| 49 | + ProductVariation::class, | |
| 50 | + 'id', | |
| 51 | + 'post_id', | |
| 52 | + 'object_id', | |
| 53 | + 'post_id' | |
| 54 | + ); | |
| 38 | 55 | } |
| 39 | 56 | } |