How to set Dynamic update to be true for all models?

I want to set all the models to useDynamicUpdate. I didn't find the global setting in model Features.

And Is there any advantages when the dynamicUpdate is set to be false?



2.8k

And is there any method like useDynamicCreate() ? Because most column values is also not necessary when creating an object.



35.2k

You can create a BaseModel and all the other models can extend the Base one

class MyBaseModel extends \Phalcon\Mvc\Model
{
    public function initialize()
    {
        $this->useDynamicUpdate(true);
    }
}
class ExampleModel extends MyBaseModel
{
    // use parent::initialize if you need a initialize() method here
    public function initialize()
    {
        parent::initialize();

        // Your code 
        // ....
    }
}

No, there is no useDynamicCreate() method. But you can skip columns. Check https://docs.phalconphp.com/en/latest/reference/models.html#skipping-columns



67.7k

I want to set all the models to useDynamicUpdate. I didn't find the global setting in model Features.


class BaseModel extends Phalcon\MVC\Model {
    public function initialize()
    {
        $this->useDynamicUpdate(true);
    }
}

// next model

Class MyFirstmodel extends **BaseModel** {
    public function initialize()
    {
        parent::initialize();
    }

    //bla bla bla 
}

// and so on and so on

And is there any method like useDynamicCreate()

this one i dont understand. Lets say we have a table with 3 fields -> id ( int AI ), name ( varchar 255, default null ), deleted ( bool) default false )

if you do


$rec = new \MyTableModel();
$rec->name = 'koko';

the insert would be:

1 | koko | false

so.. it will write values you defined, but it would also respect how you sctuctured your databases



2.8k

Thanks! And why is the default value of DynamicUpdate to be false. Is there any benefits?

You can create a BaseModel and all the other models can extend the Base one

class MyBaseModel extends \Phalcon\Mvc\Model
{
   public function initialize()
   {
       $this->useDynamicUpdate(true);
   }
}
class ExampleModel extends MyBaseModel
{
  // use parent::initialize if you need a initialize() method here
   public function initialize()
   {
       parent::initialize();

      // Your code 
      // ....
   }
}

No, there is no useDynamicCreate() method. But you can skip columns. Check https://docs.phalconphp.com/en/latest/reference/models.html#skipping-columns