public function saveLinkTable($record) { $linkTable = $this->linkTable(); $ownForeignKey = $this->createForeignKey($this->source()); $ownForeignKeyId = $record->id(); $property = $this->target(); $associated = $record->{$property}; $targetForeignKey = $this->createForeignKey($this->target()); if (empty($associated)) { return true; } foreach ($associated as $obj) { $success = BaseRecord::insertAll($linkTable, [$ownForeignKey => $ownForeignKeyId, $targetForeignKey => $obj->id()]); if (!$success) { return false; } } return true; }
public function testInsertAll() { $this->assertEquals(true, BaseRecord::insertAll(Mock::tableName(), ['name' => 'new'])); }