Determining if an object exists in the datastore

To check an object for existence in the datastore, use the exists method:

$obj->exists()

if ($foo->exists) {
    print "Foo $foo already exists!";
}

To test for the existence of an unloaded object, use the 'exist' method:

Class->exist( \%terms )

if (MT::Foo->exist( { foo => 'bar' })) {
    print "Already exists!";
}

This is typically faster than issuing a count call.

This page was last updated on 2008-10-01, 17:07.

Leave a note

Have a question? Please use the MT Forums. Notes submitted on documentation should pertain to tips & hints regarding documentation. Your note may be removed once its contents have been integrated into the body of the page.