There are three different flavors, if we might call them that, by which we can set property (field and attribute) values on our entity. They all lead to the same result. The following few code snippets can be copied and pasted into our Crud
class execute
method for testing, simply by replacing /* CRUD Code Here */
with one of the following code snippets:
//Simple model, creating new entities, flavour #1 $department1 = $this->departmentFactory->create(); $department1->setName('Finance'); $department1->save(); //Simple model, creating new entities, flavour #2 $department2 = $this->departmentFactory->create(); $department2->setData('name', 'Research'); $department2->save(); //Simple model, creating new entities, flavour #3 $department3 = $this->departmentFactory->create(); $department3->setData(['name' => 'Support']); $department3->save();
The flavour #1
approach from the preceding code is probably the preferred way of setting properties...