The existing data required by the data writer could not be found.

Jeremy P

XenForo developer
Staff member
Is there any reason at all that I can fetch a database row from a model, try to modify it via a datawriter by passing the row to setExistingData(), and have it return that the existing data could not be found?

I am able to do this with the same datawriter without error in other actions, and a dump shows the row is being fetched correctly. I'm genuinely lost as to why this is happening.

This is occurring in attachmentPostDelete() for a custom attachment handler, it attempts to fetch a row in a custom table by it's attachment_id, and then set that row in a datawriter to delete it.

AttachmentHandler..
PHP:
public function attachmentPostDelete(array $attachment, Zend_Db_Adapter_Abstract $db)
{
$photo = $this->_getAlbumModel()->getPhotoByAttachmentId($attachment['attachment_id']);

$dw = XenForo_DataWriter::create('Album_DataWriter_AlbumPhoto');
$dw->setExistingData($photo);
$dw->delete();
}

Model..
PHP:
public function getPhotoByAttachmentId($attachmentId)
{
return $this->_getDb()->fetchRow('
SELECT *
FROM album_photo
WHERE album_photo.attachment_id = ?
', $attachmentId);
}
 
Top Bottom