Have done some more testing and now I’m thoroughly confused. This is with my three level master/detail/sub-detail hierarchy again.
Firstly, if I leave moAllInOneFetch disabled everywhere, i.e. the default, then I get two round trips to the server. Why not three? Surely with this option disabled, each table data retrieval should be a separate round trip? The detail table has a where clause applied to retrieve all records for the single master I’ve retrieved. The sub-detail table has a where clause applied to retrieve all records for the currently selected detail record. If I move to another detail record then another round trip is performed to retrieve data for that detail. I notice that these sub-detail records do not replace the ones already retrieved but simply add to them, so as I iterate through each detail record, the sub-detail gradually fills up with all relevant records and I can return to a previously selected detail record without retrieving its sub-detail again.
I guess the above makes sense but sometimes it’d be useful to retrieve all the sub-detail rows in one go, as if I know I’ll be iterating through all the detail rows anyway, it would negate the need for separate trips to the server each time. I suppose the difficulty here is that it’d have to generate a where clause on the sub-detail which included every parent detail ID.
Secondly, if I enable moAllInOneFetch on the master table only, I get a single round trip to the server but this only retrieves the master and detail tables, no sub-detail is retrieved at all. The SQL for the detail table lacks any where clause so all rows are being retrieved from the database, although only the relevant ones end up in the table.
Lastly, if I enable moAllInOneFetch on both the master and detail tables then I get a single round trip to the server which retrieves all three tables. Again there are no where clauses on the detail or sub-detail SQL queries so everything is retrieved. In this case, as all detail and sub-detail rows have been retrieved, iterating through the detail rows doesn’t cause any more trips to the server as it obviously has the data already.
What I can deduce from all this is…
It seems that moAllInOneFetch needs to be the same on both the master and detail tables. If I set it on just the master then it breaks and no sub-detail is ever retrieved.
I can’t work out why, when I leave moAllInOneFetch disabled everywhere, I only get two round trips to the server instead of three, one for each table.
I seems that I have a choice between two extremes. Either I leave moAllInOneFetch disabled, in which case the where clauses are generated and only the necessary rows are returned, but then iterating through the detail rows creates a new round trip to the server each time to get the associated sub-detail. The other extreme is to enable moAllInOneFetch, which retrieves everything in a single round trip but retrieves every detail and sub-detail row from the database.
What I want is a middle-ground. I want to get everything in a single round trip to the server but only the necessary rows, i.e. all details for the master and all sub-details for all details for the master. Is this possible in any way? The only possible way I can see of doing this is to leave moAllInOneFetch enabled everywhere then generate my own where clauses on the detail and sub-detail. The former is easy but I can only do the latter if I propagate the master foreign key from the detail table down to the sub-detail so I can do something like “where sub-detail.masterid = X”.
If you could please shed some light on this for me I’d appreciate it as I’m rather confused.
Thanks