addOne

xPDOObject::addOne()

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

Syntax

API Docs: http://api.modxcms.com/xpdo/om/xPDOObject.html#addOne

boolean addOne (
   mixed &$obj,
   [string $alias = '']
)

Example

Add a Rank to a newly-created Person, then save both through cascading.

$person = $xpdo->newObject('Person',1);
$person->set('fname','Johnny');
$person->set('lname','Benjamins');

$rank = $xpdo->newObject('Rank');
$rank->set('title','CEO');
$rank->set('level',1);
$person->addOne($rank);

$person->save(); // will save both person and rank

See Also

Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab) or become an editor of the MODX Documentation.