Quote from: markh at Nov 14, 2014, 06:21 AMHuh, how can you extend it without creating a new class?
You create a custom table for the extra fields, then make modResource a related object of the custom object (which extends modResource). The class_key is still modDocument.
$data = $modx->getObject('resourceData', array('resourcedata_id' => 23));
$resource = $data->getOne('Resource');
You can no longer do this:
$resource->getOne('Data');
You can, however, do fast queries on the custom table and use getObjectGraph() on it to query it in combination with the resource fields.
$c = $modx->newQuery('resourceData');
$c->where(array('Resource.pagetitle' => 'Home'));
$resource = $modx->getObjectGraph('resourceData', '{"Resource":{}}', $c);
$resources = $modx->getCollectionGraph('resourceData', '{"Resource":{}}', $c);
Or for users, get the user, the custom data, and the profile all at once:
$c = $modx->newQuery('userData');
$c->where(array('User.username' => 'BobRay'));
$user = $modx->getObjectGraph('userData', '{"Profile":{},"User":{}}', $c);
$users = $modx->getCollectionGraph('userData', '{"Profile":{},"User":{}}', $c);
This way, the custom class will work with multiple other custom classes that extend the same object (like Articles), which wouldn't allow you to do $article->getOne('Data').