我的目標是一個表中的所有實體對象,以用相同的數(shù)據(jù)填充另一個表。我想將在 CardBalances 表中找到的結(jié)果設(shè)置為通過第一個表中的相同 card_id 找到的 Balances 表。我寫了方法,但它拋出錯誤:“調(diào)用數(shù)組上的成員函數(shù) setBalance()”(所有對象的錯誤)我得到的最接近的是:$newBalance = null; $existingBalances = $this->getCardBalanceRepository()->findBy(['gpsCard' => $gpsCard]); foreach ($existingBalances as $balance) { $id = $gpsCard->getId(); if(isset($id)) { $newBalance = $existingBalances; } else { $newBalance = new Balance(); $this->em->persist($newBalance); } $newBalance->setBalance($balance->getBalance()); $newBalance->setCurrency($balance->getCurrency()); $newBalance->setisMain($balance->getisMain()); } $this->em->flush();如果它們不在數(shù)據(jù)庫中,我想設(shè)置數(shù)據(jù),如果要更新現(xiàn)有的。
1 回答

慕虎7371278
TA貢獻1802條經(jīng)驗 獲得超4個贊
你需要改變
$newBalance = $existingBalances;
至
$newBalance = $balance;
因為 $existingBalances 是一個數(shù)組。
- 1 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報
0/150
提交
取消