From 57ee9b163e2f4dfedfebb508cc81c10a2293410e Mon Sep 17 00:00:00 2001 From: Alban Jubert Date: Sun, 27 Mar 2016 11:27:41 +0200 Subject: [PATCH] Example to add or update an related record using an associative array --- .gitignore | 1 + README.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 62b5eef..53e2ef0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.lock +.idea/ /vendor/ /tests/report/ \ No newline at end of file diff --git a/README.md b/README.md index a3bac3a..ce98e7f 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,8 @@ You can even set related models as associative arrays like this: ```php $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(); ``` 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.