public function saveReferenced(IRecord $record, $data) { $db = $this->mapper->getDb(); $ids = $db->delete($this->connectingTable)->where("%n = %i", $this->localKey, $record->getPrimary())->execute(); if (count($data)) { $q[] = "insert into [{$this->connectingTable}]"; foreach ($data as $referencedRecord) { $referencedRecord->save(); $q[] = array($this->localKey => $record->getPrimary(), $this->referencedKey => $referencedRecord->getPrimary()); } $db->query($q); } }
public function saveReferenced(IRecord $record, $data) { $this->setReferenced($record, $data); $pks = array(); foreach ($data as $item) { $item->save(); $pks[] = $item->getPrimary(); } $cls = $this->referencedEntity; $q = $this->mapper->getDb()->delete($cls::getMapper()->getTable())->where(array($this->column => $record->getPrimary())); if (!empty($pks)) { $q->and("%n not in %in", $cls::getConfig()->getPrimaryColumn(), $pks); } $q->execute(); }