laravel-responder icon indicating copy to clipboard operation
laravel-responder copied to clipboard

Transformer mappings circular dependencies

Open mauriciovillam opened this issue 5 years ago • 0 comments

Hey there, thanks for this awesome package. This particular issue has been mentioned and fixed previously in #106. I've got this:

class VariationTransformer extends Transformer
{
    protected $load = [
        'product' => ProductTransformer::class
    ];

    public function transform(Variation $model): array
    {
        return [
            'id' => $model->id,
            'sku' => $model->sku,
            'name' => $model->name
        ];
    }
}

And this.

class ProductTransformer extends Transformer
{
    protected $load = [
        'variations' => VariationTransformer::class
    ];
    
    public function transform(Product $model): array
    {
        return [
            'name' => $model->name,
            'description' => $model->description
        ];
    }
}

The problem seems to be caused by the $load relationships calling each other. I'm using the latest version (3.1.2).

mauriciovillam avatar Dec 11 '20 01:12 mauriciovillam