[Coldbox 4.3] Recommendations for how to handle orm post load data formatting and orm events

30 views
Skip to first unread message

David

unread,
Jun 21, 2017, 10:30:45 AM6/21/17
to ColdBox Platform
The goal is to format things like vendor phone numbers and tax id numbers after they are pulled from the database, and to strip formatting before they are stored in the database. 

We have been using the orm event handler events and an interceptor that formats the data ORMPostLoad and then strips the formatting on ORMPreUpdate/ORMPreInsert, But we now have an issue when we fire another interceptor to create alerts from the vendor orm objects preinsert/preupdate methods. In the async alert interceptor we save an alert which flushes the orm session and resaves the vendor (because it thinks its dirty due to the formatting change) which retriggers the  preinsert/preupdate methods on the model and causes duplicate alerts to be created. 

I tried hooking into the presave event instead but I get the same behavior. I am thinking maybe I am going about the whole thing wrong and need some advice on how it could be done better.

Jon Clausen

unread,
Jun 21, 2017, 10:49:43 AM6/21/17
to col...@googlegroups.com

This really isn’t a ColdBox issue, per se, but more of an ORM event handling question.

The issue sounds like an ORM mapping issue.  How are the alerts mapped to the vendor and how are the saves of the alerts being handled within the async interception. 

Since these alerts are predicated on a state change to the vendor, I would suggest using the `postInsert` and `postUpdate` interception points, instead.

I would also suggest using the PK of the vendor (instead of passing the object) and using the `new()` or `populate()` methods for creating the alerts.  This ensures that the vendor entity being loaded in the async thread is clean.

 

HTH,

Jon

--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/d8d81457-189d-4d7e-af67-eae286cb2fa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David

unread,
Jun 21, 2017, 2:52:46 PM6/21/17
to ColdBox Platform
True its not strictly a coldbox issue, but the postload interceptor is what starts the problem by applying the formatting and making the object always dirty. It when combined with the async alert interceptor that has to retrieve the vendor object causes the duplication. There is no "real" relationship between alert and vendor because an alert can be tied to a number of different object types. I guess my question is more about what is the recommended design pattern for formatting data after the object is retrieved and stripping it before its saved to the database. Everything I can think of seems to fail in this scenario. 

Matt Quackenbush

unread,
Jun 21, 2017, 3:02:24 PM6/21/17
to col...@googlegroups.com
If I have understood the situation correctly ... the database should store unformatted numbers but you want to display them in a particular format ... then you should have some sort of `getPhoneNumberFormatted()` method on your class, and not even touch the actual data. 

To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+unsubscribe@googlegroups.com.

To post to this group, send email to col...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages