Interesting. Thanks for the clarification on this.
Is it worthwhile submitting a feature request to expose this type of action via a more user-friendly API method? Use of
call_user_func_array() seems really out of place.
The overall problem I’m trying to solve here is loading an *ENTIRE* object. It makes good sense that xPDO doesn’t immediately load up all composite/aggregate fields, but there are times when that is exactly what should be done. E.g. this is
exactly how a schema-less system such as MongoDB would store/retrieve an object: as a nested data structure, not divided into arbitrary tables.
I still don’t really understand what hydration means, but what leaps to mind is exactly what I’m trying to do here: get a full instance of an object, with all related fields available with their values. E.g. a blogpost with all its comments might be represented as an object such as:
$blogpost = $modx->getEntireObject('Blogpost', 123); // <-- my fictitious function
print_r( $blogpost->toArray() );
// Contains something like:
array(
'title' => 'My Title',
'content' => 'This is my post...',
'Comments' => array(
array('content' => 'My first comment...'),
array('content' => 'Other comment...'),
array('content' => 'Third comment.'),
)
);
I can imagine an option in the getObject method where you could specify LOAD_ALL or a "getEntireObject" method (as above) that specifies to fetch all related fields. I could also imagine that you could define limits to the depth of the retrieval. E.g. "fetch the first 10 comments unless I override it". Each of the composite/aggregate relationships represents additional queries, so it makes sense that you might be able to tap into the limits/offset or other criteria for each of those relationships, but the point is that it would be extremely useful to be able to tap into that stuff immediately when you request the object, and not manually "by-hand" when writing out how to load up all of an object’s relations.
Did that make sense? I can come up with my own function that iterates through an object instance and fetches all the related objects, but it seems plausible that this type of action could/should be available in the xPDO core. I’d bet this could even be done in a way that didn’t perform the joins until a field is requested...