ptitcoutu opened a new issue, #14396:
URL: https://github.com/apache/grails-core/issues/14396

   When I change an embedded object to another instance of the same class but 
with some fields which have no values, those fields are not updated.
   For example with a class Position and a field address with several fields as 
described below :
   
   ```groovy
   class Position {
       Address address
       static embedded = ['address']
       static constraints = {
           address nullable: true
       }
   }
   
   class Address {
       String streetAddress1
       String streetAddress2
       String streetAddress3
       String postalCode
       String city
   
       CountryCode countryCode
   
       String formattedAddress
       static mapping = {
           // No versioning, address is only a embedded object
           version false
       }
   }
   ```
   
   If I have a position with an address with city = Paris and country = FR, 
when I want to update the position and I use et new address with just country = 
ES in mongodb I see an address with city = Paris and country = ES. 
   
   I should have an address with just country = ES and no city.
   
   When I try to debug my application I see that the 
   
   org.grails.datastore.mapping.mongo.engine.codecs.PersistentEntityCodec 
doesn't manage correctly the embedded use case because encodeEmbeddedUpdate 
call encodeUpdate with a value but without the embedded set to true. This issue 
cause the property with null value to be ignored instead of being set to null.
   
   **Workaround** : to ensure the correct behavior of the udpate I changed my 
service to markDirty all the properties of my address class. It's no really 
cleaned but I didn't any other solution.
   
   **Context** :
     Grails : 4.0.0
     GORM : 7.0.0.RELEASE
     Groovy : 2.5.6 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to