Avatar

Trip.device vs Trip.device_id

0

HI there
I would like to understand why the Trip data contains an entire Device object as a field, instead of just a device_id that could then be used to correlate back to an entry in the Device data?

This isn't a complaint, it's more about wanting to understand why and how the various entities relate to each other..

 

Michael

Michael Lovett

Please sign in to leave a comment.

1 comment

0
Avatar

Hi Michael,

Nested entities (objects with unique identifiers) will have only the id of the object populated. This is by design and is intended to save time/weight over the wire by not sending large amounts of redundant or useless information.

The nested entity is returned as an object rather than an ID for convenience. It's very common to populate nested entities in client process. ex: foreach trip in trips => trip.device = devices_lookup[trip.device.id].

Thanks,

Steve

Steve Hansen 0 votes