Listing 13.6. Doctrine: implementacja metody insertIfNotExists()
public static function insertIfNotExists($panstwo)
{
    $q = Doctrine_Query::create()
        ->from('Panstwo p')
        ->where('p.nazwa = ?', $panstwo);
    $obj = $q->fetchOne();
    if (!$obj) {
        $obj = new Panstwo();
        $obj['nazwa'] = $panstwo;
        $obj->save();
    }
    return $obj;
}
