# |
Dec 17th 2017, 20:02 |
saeideng |
// In a controller. $articles = TableRegistry::get('Articles'); $list = $articles->find('popular')->toArray(); $patched = $articles->patchEntities($list, $this->request->getData()); foreach ($patched as $entity) { $articles->save($entity); } |
# |
Dec 17th 2017, 20:02 |
saeideng |
book.cakephp.org says |
# |
Dec 17th 2017, 20:01 |
saeideng |
do you think my code syntax is true? |
# |
Dec 17th 2017, 20:01 |
saeideng |
``` $list=$this->Models->find()->toArray(); $list = $this->Models->patchEntities($list, [0=>['field'=>12]]);dd($list); ``` |
# |
Dec 17th 2017, 20:00 |
joop |
without this its hard to tell anything |
# |
Dec 17th 2017, 19:56 |
joop |
? |
# |
Dec 17th 2017, 19:56 |
joop |
okey lets again,how did you try to save? with foreach and save entity or withjust savemany entities |
# |
Dec 17th 2017, 19:55 |
saeideng |
debug();die; |
# |
Dec 17th 2017, 19:54 |
joop |
what is dd(...) i have never used this command |
# |
Dec 17th 2017, 19:54 |
saeideng |
:slightly_smiling_face: |
# |
Dec 17th 2017, 19:54 |
saeideng |
I pretty sure |
# |
Dec 17th 2017, 19:53 |
saeideng |
I can see records `$list=$this->Models->find();dd($list)` |
# |
Dec 17th 2017, 19:53 |
joop |
just for check the database entities |
# |
Dec 17th 2017, 19:53 |
joop |
i know its not related |
# |
Dec 17th 2017, 19:53 |
saeideng |
not related to DB |
# |
Dec 17th 2017, 19:52 |
joop |
do you have acces for database server? |
# |
Dec 17th 2017, 19:52 |
saeideng |
return new entity |
# |
Dec 17th 2017, 19:52 |
saeideng |
$list = $this->Models->patchEntities($list, [0=>['field'=>12]]);dd($list); |
# |
Dec 17th 2017, 19:52 |
joop |
are those created fresh? |
# |
Dec 17th 2017, 19:52 |
saeideng |
$this->Models->find() |
# |
Dec 17th 2017, 19:51 |
saeideng |
I have some record in DB |
# |
Dec 17th 2017, 19:51 |
joop |
same datas but different id-s |
# |
Dec 17th 2017, 19:51 |
joop |
i mean new instances |
# |
Dec 17th 2017, 19:51 |
saeideng |
what you mean? |
# |
Dec 17th 2017, 19:51 |
saeideng |
new entity? |
# |
Dec 17th 2017, 19:51 |
joop |
do you have new entities in the mysql table? |
# |
Dec 17th 2017, 19:50 |
saeideng |
https://github.com/cakephp/cakephp/blob/master/tests/TestCase/ORM/TableTest.php#L5685 |
# |
Dec 17th 2017, 19:50 |
saeideng |
maybe |
# |
Dec 17th 2017, 19:48 |
joop |
if i good understand you have the same issue as mine? |
# |
Dec 17th 2017, 19:48 |
saeideng |
but not related |
# |
Dec 17th 2017, 19:48 |
saeideng |
just there is a testCase for this |
# |
Dec 17th 2017, 19:47 |
saeideng |
I will open issue for this |
# |
Dec 17th 2017, 19:47 |
joop |
in my case i want to also update somefields, but it makes new entities insted of updateng the correspond fields |
# |
Dec 17th 2017, 19:46 |
saeideng |
with/without `toArray()` returns isNew() //true |
# |
Dec 17th 2017, 19:46 |
joop |
you will be amaezed but i face something similar too |
# |
Dec 17th 2017, 19:45 |
joop |
try to not make array from the $list |
# |
Dec 17th 2017, 19:44 |
joop |
aha |
# |
Dec 17th 2017, 19:44 |
saeideng |
update multi entities at one time |
# |
Dec 17th 2017, 19:44 |
joop |
and than you want to save where? |
# |
Dec 17th 2017, 19:44 |
joop |
you make a find to get the popular articles |
# |
Dec 17th 2017, 19:44 |
joop |
so lets clear the scenerio what is your goal? |