Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parent mapper not called in child #70

Closed
pedrem opened this issue Jun 20, 2024 · 1 comment · Fixed by #76
Closed

Parent mapper not called in child #70

pedrem opened this issue Jun 20, 2024 · 1 comment · Fixed by #76

Comments

@pedrem
Copy link

pedrem commented Jun 20, 2024

Hey,

I've come across a possible imitation. I have a DTO extending another that has a property mapper. What I assumed would happen is for the parent's mapper to run, but that doesn't seem to be the case. I would like the mapper for the parent to run, otherwise we'll have to duplicate the mapper.

Example:

class ProductWithFeaturedDto extends ProductDto
{
    public ?bool $featured = false;
}
#[AsPropertyMapper(targetClass: ProductDto::class)]
class ProductDtoMapper
{
    #[AsPropertyMapper]
    public function mapBaseCost(Product $product): ?float
    {
        $price = $product->getPrices()->first();
        if ($price) {
            return round($price->getPriceRrp(), 2);
        }

        return null;
    }
 }

Both DTOs are getting mapped from the same source, if that helps.

We've tried using it like, but attribute is not repeatable.

#[AsPropertyMapper(targetClass: ProductDto::class)]
#[AsPropertyMapper(targetClass: ProductWithFeaturedDto::class)]
class ProductDtoMapper

Could you let me know if this is something that can be achieved?

@priyadi
Copy link
Member

priyadi commented Jun 21, 2024

should be fixed in the related PR. also tagged v1.5.1 for this. thank you for your report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants