Jump to main content Jump to doc navigation

xPDOManager::removeObjectContainer()

Drops a table if it exists.

This will only work if there is a corresponding xPDO class for the table and its package has been loaded. MODX will not drop the table if the ORM layer has not defined the table.

Syntax

boolean removeObjectContainer (string $className)

Examples

Drop the table associated with the “Person” object:

$manager = $xpdo->getManager();
$manager->removeObjectContainer('Person');

Alternatives

If you are trying to remove tables after having removed or renamed the underlying xPDO classes, you may need to resort to issuing a manual “DROP TABLE” query.

$removed = $modx->exec('DROP TABLE IF EXISTS your_table');
if ($removed === false && $modx->errorCode() !== '' && $modx->errorCode() !== PDO::ERR_NONE) {
    print 'Could not drop table! ERROR: ' . print_r($modx->pdo->errorInfo(),true);
}
else {
    print 'Table dropped successfully.';
}

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$194 per month—let's make that $500!

Learn more