puzzled by Resource.php

2 posts / 0 new
Last post
puzzled by Resource.php

There is a function in Resource.php that is puzzling me.

    private function RemoveAssociation($TableName, $FieldName, $Value, $Field = NULL)
        # start out assuming no association will be removed
        $AssociationRemoved = FALSE;
        # convert value to array if necessary
        $Values = is_array($Value) ? $Value : array($Value);
        # for each value
        foreach ($Values as $Value)
            # retrieve ID from value if necessary
            if (is_object($Value)) {  $Value = $Value->Id();  }
            # remove any intersections with target ID from DB
            $this->DB->Query("DELETE FROM ".$TableName
                    ." WHERE ResourceId = ".intval($this->Id)
                    .($Field ? " AND FieldId = ".intval($Field->Id()) : "")
                    ." AND ".$FieldName." = ".intval($Value));
        # report to caller whether association was added
        return $AssociationRemoved;

Where is $AssociationRemoved ever set to TRUE?


(There is an analogous structure (I think) in AddAssociation where $AssociationAdded is explicitly set to TRUE.)

Re: puzzled by Resource.php

Looks like a bug, though I'm not sure of the practical impact, since I think the return value of that method is usually not checked.  Anyway it's fixed in the patch that I uploaded in this thread.