geocoder-php/BazingaGeocoderBundle

Using attribute "Address" on getter will always trigger geocoding

fnagel opened this issue · 2 comments

fnagel commented

Using the attribute on a property will only trigger geocoding on change, but using using the #[Geocoder\Address] attribute on a getter method will always trigger geocoding. Is that on purpose?

Looks like this is caused by this guard clause: https://github.com/geocoder-php/BazingaGeocoderBundle/blob/962834628d63ad15a8b5d40ff2da764c73dcde65/src/Doctrine/ORM/GeocoderListener.php#L126C9-L128

I guess there is no easy way to fix this, right? Using #[Geocoder\Address] on multiple properties (like $street $zip, $city, ...) will not work either. Can we add a parameter to the Address attribute / annotation for passing an array of properties?

Any ideas?

Related to #239 and #281

If you use a getter for address, then there is no way to get the change set to detect if the address has changed, therefore I think it's not feasible

Only solution I can think of if we'd introduce some geocodeIf: expression property on the Address attribute.
For example:

#[Geocoder\Address(geocodeIf: 'this.isAddressChanged()')]
public function getAddress(): string { ... }
public function isAddressChanged() { ... }

Or something like that.