views:

48

answers:

1

Why does my cfc method (when returning JSON format or called via remoting) return all related objects regardless of the lazy setting on the property?

+1  A: 

My guess is that when CF serializes those objects into JSON, it is forced to call the getters for the related objects, which in turn causes them to looked up in the database. The "lazy" property controls whether or not related objects are retrieved during the retrieval of the main objects or delayed until you actually request them. In this case, when serializing the object, the related objects are either looked up or not based on the JSON returned, so regardless of the lazy setting, they'll come back.

Basically, if you have a data structure of baseball players and teams, if the JSON returned for a selected player (i.e. Josh Beckett) calls for info about the team (i.e. Red Sox), regardless of the lazy property setting, that team object will either be retrieved when you get the player object or when you ask for the team object that relates to the player.

Make sense?

Bialecki
Yeah, makes sense. It appears if I relate the objects in 2 locations, the first fetches them and the second doesn't.
E-Madd
When you say "fetch," do you mean actually hits the database? I would guess that's because it's able to cache the results from the first query to use with the second request.
Bialecki