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

Mapper doesn't differentiate between property and getter #168

Open
klunejko opened this issue Jun 21, 2024 · 0 comments
Open

Mapper doesn't differentiate between property and getter #168

klunejko opened this issue Jun 21, 2024 · 0 comments

Comments

@klunejko
Copy link

I ran into an issue where a target object wasn't populated as expected, due to the getter being the same name as the protected property.

//source: Order::class (abbreviated)

/** @var ?LineItem[] */
protected ?array $lineItems = null;

/**
 * @return ?LineItem[]
 */
public function getLineItems(
): ?array {
    return $this->lineItems;
}
//target: CartView::class (abbreviated)

/** @var ?LineItem[] $items */
#[MapFrom(source: Order::class, property: 'line_items')]
public ?array $items = null;

After dumping the GeneratorMetaData, I noticed that lineItems was being ignored, with the following reason: "Property cannot be read from source, and the attached transformer require a value.".

Not sure if it's an actual issue with the symfony property component itself, but it looks like after detecting the getter for "line_items", it then tries to use the protected method directly.

And is there maybe a way to specify the method directly? For now, I've just added a wrapper method that calls getLineItems, but that's obviously not ideal.

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

No branches or pull requests

1 participant