Browse Source

Example to add or update an related record using an associative array

tags/1.0.1
Alban Jubert 9 years ago
parent
commit
57ee9b163e
  1. 1
      .gitignore
  2. 3
      README.md

1
.gitignore vendored

@ -1,4 +1,5 @@
*.lock *.lock
.idea/
/vendor/ /vendor/
/tests/report/ /tests/report/

3
README.md

@ -113,7 +113,8 @@ You can even set related models as associative arrays like this:
```php ```php
$project = Project::findOne(1); $project = Project::findOne(1);
$project->company = ['name' => 'GiHub', 'description' => 'Awesome']; $project->company = ['name' => 'GiHub', 'description' => 'Awesome']; // Will create a new company record
// $project->company = ['id' => 3, 'name' => 'GiHub', 'description' => 'Awesome']; // Will update an existing company record
$project->save(); $project->save();
``` ```
Attributes of the related model will be massively assigned using the `load() method. So remember to declare the according attributes as safe in the rules of the related model. Attributes of the related model will be massively assigned using the `load() method. So remember to declare the according attributes as safe in the rules of the related model.

Loading…
Cancel
Save