将文件链接到Doctrine中的一行

I want to link a physical file with a row in a table. My intention is to use database habilities to delete the files that are referenced in the table. For example:

$o = Doctrine::getTable('Document')->find(12); $o->delete();

This code delete the row in the table, i want to delete an hipotetical file referenced in $o->file_location. I'm trying it with Events (preDelete, postDelete, preUpdate, postUpdate) but i can't make it works.

can't you just unlink the file?

like this:

$o = Doctrine::getTable('Document')->find(12);
if(unlink($o->file_location))
{
    $o->delete();
}

In your Document model i would add something like this:

class Document extends BaseDocument
{
    ...

    public function preDelete($event)
    {
        unlink($this->file_location);
    }

    ...
}

Also, Doctrine has the Doctrine_Search_Files class which indexes (directories of) files for searching. Maybe you can get some inspiration there?