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…
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
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.