Delete attribute value from single page editing interface

Permalink
Hey guys!
I'm trying to achieve the following: I want to list a bunch of pages on a dashboard single page. The pages have a custom attribute type associated with them. For each page entry, there is a delete button. The delete button should delete the attribute value entries from database, and the page itself. I have a delete task inside my single page's controller.

public function delete($cID){
    $p = Page :: getByID($cID);
    $av = $p -> getAttribute('reference');
    $av -> delete();
    $p -> delete();
}


The error I get is:

Fatal error: Call to a member function deleteValue() on a non-object in <c5root>/concrete/core/models/attribute/value.php on line 106

However, if I check the class of $av with get_class($av), it clearly says ReferenceAttributeTypeValue. This class extends the AttributeValue class. Other code depending on the existence of the given attribute work fine, database entries are intact. Any hints on what could the problem be?