Problem with requesting Raw Value

Hi, In my database a field in the tabel Customer is set to Null. The table appointments is connected via a foreign key (customerid). Now when I access this field via $appointment->Customer->getField() everything works fine and I can validate if the field is Null for example via if($appointment->Customer->getField() == Null). Now I do some other things and save a different field into $appointment. If I now request again the field in the Customer table with $appointment->Customer->getField(), I get an object(Phalcon\Db\RawValue)#293 (1) { ["value":protected]=> string(4) "NULL" }. Why does this change? And I don't want to validate every time for if($field == Null and $field == "NULL) Thanks for your help. I hope, you undestand what I mean ;)

edited Jan '16


you may need a model behavior:


use Phalcon\Mvc\Model;

class Robots extends Model
    public function initialize()
        // Skips only when updating

Hi, Thank you for your answer. I think I found a solution how to prevent the problem, although I still don't really understand the problem: Previously on validation in the model, I set a (new RawValue('NULL')), even when the field was already null. After saving the object, and requesting it again, I got the object(Phalcon\Db\RawValue)#293 (1) { ["_value":protected]=> string(4) "NULL" } instead of null. Now if I don't set the new RawValue('NULL') if its already null,the problem doesn't appear anymore, but it doesn't really solve the problem. @le51 your answer is also more a workaround, isn't it? Does anyone has an idea how to solve the problem? Thanks ;)


@le51 your answer is also more a workaround, isn't it?

Sure !