sim51/logisima-play-neo4j — Issue #16: Can't add model objects inside wrapper objects as original properties are lost.
Author: jph303
Created: 2012-02-26 15:19:41+00:00
State: open

Not sure if this is really a bug or a feature enhancement, but thought i would ask if this is possible:

I was trying to simplify my code a little a pass a UserDTO which contained a few additional properties and the User model object to my view and back to the controller. I found that as soon as a model object was wrapped in another object (the DTO) its original properties that where not fields on the view where lost. The most important one of these properties was Node, because if this is null the Neo4jFactory will create a new User node in the Graph. So every time i tried to edit a user a new user was being created. For example:

this works:

render(user, userDTO);
view contains :
save(User user, UserDTO, userDTO);

where the userDTO just contains other information and not the User object.

but if I add user as a property inside the UserDTO so the above becomes:

render(userDTO)
view contains :
save(userDTO)

The userDTO.user.node property is null as are all other properties that are not fields on the form. So i have to load up the the User from the graph in the save method and then transfer all the form properties to it like this:

User dtoUser = userDTO.user;

User user = User.getByKey(userDTO.user.key);
user.firstName = dtoUser.firstName;
....
user.save();

Is there away around this, or should i just pass models in separately as in the first example??