Skip to content

Commit e326e27

Browse files
authored
Merge pull request #8001 from cakephp/5.next-findorcreate
findOrCreate() with data array.
2 parents 807731b + 200b4ae commit e326e27

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

en/appendices/5-2-migration-guide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ Datasource
101101
This allows you to create dynamic validation messages based on the entity
102102
state and validation rule options.
103103

104-
105104
ORM
106105
---
107106

108-
- ``CounterCacheBehavior::updateCounterCache()`` has been addded. This method
107+
- ``CounterCacheBehavior::updateCounterCache()`` has been added. This method
109108
allows you to update the counter cache values for all records of the configured
110109
associations.
111110
- ``BelongsToMany::setJunctionProperty()`` and ``getJunctionProperty()`` were
112111
added. These methods allow you to customize the ``_joinData`` property that is
113112
used to hydrate junction table records.
113+
- ``Table::findOrCreate()`` now accepts an array as second argument to directly pass data in.
114114

115115
View
116116
----

en/orm/saving-data.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,15 @@ ideal in scenarios where you need to reduce the chance of duplicate records::
11821182
}
11831183
);
11841184

1185+
As of 5.2.0, you can provide an array of data to set into the entity when it is
1186+
created::
1187+
1188+
$otherData = ['name' => 'bobbi'];
1189+
$record = $table->findOrCreate(
1190+
['email' => 'bobbi@example.com'],
1191+
$otherData,
1192+
);
1193+
11851194
If your find conditions require custom order, associations or conditions, then
11861195
the ``$search`` parameter can be a callable or ``SelectQuery`` object. If you use
11871196
a callable, it should take a ``SelectQuery`` as its argument.
@@ -1193,6 +1202,9 @@ options for this method are:
11931202
* ``defaults`` Set to ``false`` to not set ``$search`` properties into the
11941203
created entity.
11951204

1205+
.. versionadded:: 5.2.0
1206+
Support for ``$callback`` as an array of data was added.
1207+
11961208
Creating with an existing primary key
11971209
=====================================
11981210

0 commit comments

Comments
 (0)