addMany
Last edited by Everett Griffiths on May 26, 2014.
xPDOObject::addMany()
Adds an object or collection of objects related to this class.
Syntax
API Docs: http://api.modx.com/revolution/2.2/db_core_xpdo_om_xpdoobject.class.html#%5CxPDOObject::addMany()
boolean addMany ( mixed &$obj, [string $alias = ''] )
Example
Add golf clubs to a bag and save.
$bag = $xpdo->newObject('GolfBag'); $bag->set('name',"Chris's Bag"); $bag->set('color','blue'); $clubs = array(); for ($i=1;$i<10;$i++) { $club = $xpdo->newObject('GolfClub'); $club->set('name',$i.' Iron'); $clubs[] = $club; } $bag->addMany($clubs); $bag->save(); // saves both the bag and all the clubs
Nested Calls
You can nest one addMany() call inside another and thus create all your related data via a single save() operation.
Troubleshooting
Remember that this operation is intended to be called only for objects whose relationships are defined as cardinality="many".See Also
Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).