[3.5.x] SerializeJSON, renderData, and ORM Entities using Inheritance

Hey Everyone,

I’m trying to put together a restful version of some of our API for use via ajax. I’m having a problem serializing ORM entities that use inheritance via any of the preferred ways of doing this.

What happens if I call serializeJSON or renderData(type=‘json’…) is that it only returns the properties that are NOT inherited from the super class of the ORM entity.

Does anyone have any suggestions on the best way to handle this? I’m sure I could explicitly create the struct, but I’m thinking there are perhaps a dozen or so entities that I’d need to do this on and it seems too repetitive to me…

Cheers,
Ben

I can see two approaches:

  1. Convert the entity to a query with entitytoQuery(), this will flatten the entire hierarchy for you and then you can use that to serialize it
  2. Create a utility method on the entities to retrieve a memento of its properties. You will need some recursion on this and some metadata reading. I wish CF would handle this natively for us.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

here is the base class for my orm entities.

getPropertyMemento() will do what you want.

Nice! Thanks

youre welcome!

if you have computed properties you’d like included in the memento, just include a method called flatten() in your entity which returns a struct.