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

Skip map a destination field if source's field are unset #11

Open
tuanht opened this issue Aug 26, 2015 · 1 comment
Open

Skip map a destination field if source's field are unset #11

tuanht opened this issue Aug 26, 2015 · 1 comment

Comments

@tuanht
Copy link

tuanht commented Aug 26, 2015

Skip map a destination field if source's field are unset

Problem:

  • In my Symfony project, when I map from model to entity, and persist my entity to DB. I don't need to define fields that not necessary in model. The problem are after map, entity's fields will be set to null if the same don't exists in model. So, database data are lost.
  • skipNull option should not use in this situation. Because if fields in model are null, I want them to be update to entity.

Solution 1:

  • Add option skipUnset. Then catch NoSuchPropertyException in map() function. $value will be set to null if skipUnset not used, otherwise continue the loop.

Solution 2:

  • Skip unset property in buildDefaultMap() by default.
  • In this solution, catch for NoSuchPropertyException MAY become unreach.
@tuanht
Copy link
Author

tuanht commented Aug 26, 2015

I think this is a bug. So solution 2 must be implemented

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