src/CRUDlex/MySQLData.php
protected function saveMany(Entity $entity)
    {
        $manyFields = $this->getManyFields();
        $id         = $entity->get('id');
        foreach ($manyFields as $manyField) {
            $thisField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thisField').'`';
            $thatField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thatField').'`';
            $this->database->delete($manyField, [$thisField => $id]);
            $manyValues = $entity->get($manyField) ?: [];
            foreach ($manyValues as $thatId) {
                $this->database->insert($manyField, [
                    $thisField => $id,
                    $thatField => $thatId['id']
                ]);
            }
        }
    }
protected function saveMany(Entity $entity)
    {
        $manyFields = $this->getManyFields();
        $id         = $entity->get('id');
        foreach ($manyFields as $manyField) {
            $thisField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thisField').'`';
            $thatField = '`'.$this->definition->getSubTypeField($manyField, 'many', 'thatField').'`';
            $this->database->delete($manyField, [$thisField => $id]);
            $manyValues = $entity->get($manyField) ?: [];
            foreach ($manyValues as $thatId) {
                $this->database->insert($manyField, [
                    $thisField => $id,
                    $thatField => $thatId['id']
                ]);
            }
        }
    }
protected function saveMany ( Entity $ entity ) { $ manyFields = $ this -> getManyFields ( ) ; $ id = $ entity -> get ( 'id' ) ; foreach ( $ manyFields as $ manyField ) { $ thisField = '`' . $ this -> definition -> getSubTypeField ( $ manyField , 'many' , 'thisField' ) . '`' ; $ thatField = '`' . $ this -> definition -> getSubTypeField ( $ manyField , 'many' , 'thatField' ) . '`' ; $ this -> database -> delete ( $ manyField , [ $ thisField => $ id ] ) ; $ manyValues = $ entity -> get ( $ manyField ) ? : [ ] ; foreach ( $ manyValues as $ thatId ) { $ this -> database -> insert ( $ manyField , [ $ thisField => $ id , $ thatField => $ thatId [ 'id' ] ] ) ; } } }
First, deletes all to the given entity related many-to-many entries from the DB
and then writes them again.

@param Entity $entity
the entity to save the many-to-many entries of
First deletes all to the given entity related many - to - many entries from the DB and then writes them again .