Jump to main content Jump to doc navigation

xPDOObject::getOne()

Gets an object related to this instance by a foreign key relationship.

Use this for 1:? (one:zero-or-one) or 1:1 relationships, which you can distinguish by setting the nullability of the field representing the foreign key.

Syntax

API Docs: http://api.modx.com/revolution/2.2/db_core_xpdo_om_xpdoobject.class.html#%5CxPDOObject::getOne()

xPDOObject|null &getOne (
   string $alias,
   [object $criteria = null],
   [boolean|integer $cacheFlag = true]
)

Example

Echo the email of a modUser with ID 1, which has a related object called modUserProfile, that has a field called "email" - set as "a@bc.com" for this user.

$user = $modx->getObject('modUser',1);
$profile = $user->getOne('Profile');
echo $profile->get('email');
// prints "a@bc.com"

See Also