james....@googlemail.com
unread,Jan 30, 2011, 5:12:21 AM1/30/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Outlet ORM
Hi,
I'm working with Outlet in a context where I store a business object
in a session variable. The business object is loaded from the database
using Outlet. This business object can be modified, even while it is
in the session cache:
1. Retrieve object from session variable;
2. Update object properties;
3. Commit changes to database using outlet.
While testing this out, however, I've run across a problem whereby
executing the save using Outlet throws an error. After executing the
following line in OutletMapper.getModifiedFields, the value of $data
is null:
$data = $this->get( $entityCfg->clazz, $entityCfg->getPkValues($obj) )
The reason for this is that the business object is not stored in the
Outlet cache anymore (presumably because the user page has been
changed several times since the object was first loaded).
The workaround for this is to reload the object from the database
using the ID stored in the session variable (thereby ensuring the
object is in the Outlet cache) and then update the reloaded object
rather than the stored object, as follows:
1. Get ID of object in session variable;
2. Load object from database using Outlet;
3. Update object properties;
4. Commit changes to database using Outlet.
I mention this to highlight the possibility that there may be
scenarios in which Outlet is used to update objects that are not
stored in the cache, but that are not new objects (thus Update, not
Insert is the appropriate operation). The workaround mentioned above
is not ideal - it wastes a load.
Now, here is my question: The possibility that an update might be
performed on an object not stored in the cache has obviously been
considered. The following lines can be found in the
getModifiedFields() method and handle exactly the scenario I describe:
/* not sure about this yet
// if this entity hasn't been saved to the map
if (!$data) return self::toArray($this->obj);
*/
Question: Did anyone ever make a decision as to whether or not this
was a suitable workaround?
Suggestion: In the event that an update is performed on a non-cache
object, Outlet could add the object to the cache.