Hydrating Fields
What is hydration?
Hydration is the process by which fields on objects are directly accessible for reading as public variables on the object itself.
In xPDO, this option is available by passing either of the following configuration options into the $config parameter (2nd) in the xPDO constructor:
- XPDO_OPT_HYDRATE_FIELDS - If true, fields will be hydrated.
- XPDO_OPT_HYDRATE_RELATED_OBJECTS - If true, related objects will be hydrated.
- XPDO_OPT_HYDRATE_ADHOC_FIELDS - If true, ad-hoc fields will be hydrated.
Hydrating Fields
If the XPDO_OPT_HYDRATE_FIELDS option is set to true, this ability will be available. This makes all object fields accessible for reading directly on the object. An example of this is such:
$object->set('name',$name); echo $object->name;
This would output the 'name' field of the object, assuming that the 'name' field is defined in the object's schema.
Hydrating Ad Hoc Fields
If the XPDO_OPT_HYDRATE_ADHOC_FIELDS option is set to true, this ability will be available. It takes one step further the idea of hydrating fields, and now hydrates all ad hoc fields; or rather, any field that is not defined in the schema. Say we want to set an arbitrary field called 'puns' to a Person object:
$object->set('name','Arthur Dent'); $object->set('puns',42); echo $object->name.' has '.$object->puns.' puns.';
This would echo the appropriate value, even if the field 'puns' isn't defined in the schema.
Hydrating Related Objects
if the XPDO_OPT_HYDRATE_RELATED_OBJECTS option is set to true, this ability will be available. This hydrates all related objects to public vars when getOne or getMany is used. Example:
$fordPrefect->getMany('Beers'); foreach ($fordPrefect->Beers as $beer) { echo $beer->get('name').'<br />'; }
This would echo a list of all the Beers associated to the $fordPrefect object.
See Also
Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).