useDynamicUpdate(true); not working for partial update

I am trying to update a row partially .... just change its "status" column however the "update" method of the Phalcon\Mvc\Model fails because some of the other columns are "required" in the database and it seems like the "update" method inserts nulls for those.

Here is what my model looks like ```php class MyModel extends \Phalcon\Mvc\Model {

public function getSource() {
    return 'table_name';
}

public function initialize()
{
    $this->setConnectionService('dbconn');
    $this->useDynamicUpdate(true);
}

public function myUpdate(array $data)
{
     $this->update($data);
}

```

The variable $data above in the myUpdate function contains the following ```php array('id'=>2, 'status'=>0) ```

I am using onValidationFails hook to printr() the messages and I get the following: ```php Array ( [0] => Phalcon\Mvc\Model\Message Object ( [type:protected] => PresenceOf [message:protected] => firstname is required [field:protected] => firstname [_model:protected] => )

[1] => Phalcon\Mvc\Model\Message Object
    (
        [_type:protected] => PresenceOf
        [_message:protected] => lastname is required
        [_field:protected] => lastname 
        [_model:protected] => 
    )

[2] => Phalcon\Mvc\Model\Message Object
    (
        [_type:protected] => PresenceOf
        [_message:protected] => username is required
        [_field:protected] => username 
        [_model:protected] => 
    )

[3] => Phalcon\Mvc\Model\Message Object
    (
        [_type:protected] => PresenceOf
        [_message:protected] => password is required
        [_field:protected] => password 
        [_model:protected] => 
    )

) ```

What do I need to do in order to update only the status column while leaving the other ones intact?!



7.7k

In your phpmyadmin, set nullable for those fields.



4.0k
edited Sep '14

Hello,

I am having the same problem... I only want to update some of the fields in the row and leave the others intact.

$this->setup( array('notNullValidations'=>false) );

$this->useDynamicUpdate(true);

Is this possible?

Tim



27.4k

Hi,

maybe skipping the required attributes on Update action will do the trick:

   public function initialize()
   {
       $this->skipAttributesOnUpdate(array('firstname', 'lastname'));
   }

So useDynamicUpdate(true) does not work as intended?



27.4k
edited Mar '16

did you try the trick above ?

Yes I did and It works, but my point was about useDynamicUpdate(true) not working as intended. Is this considered a bug? If so please point me to the bug because I cannot seem to find one related to this issue.

Thanks.