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

API Docs: removeObjectContainer

int 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

Budget

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

Learn more