src/Mapper/Relation/HasAndBelongsToMany.php
public function add(EntityAdded $event)
    {
        $entity = $event->getEntity();
        $collection = $event->getCollection();
        $this->deleteRelation($entity, $collection);

        $repository = $this->getParentRepository();
        $adapter = $repository->getAdapter();
        $value = $collection->parentEntity()->getId();

        Sql::createSql($adapter)
            ->insert($this->getRelationTable())
            ->set(
                [
                    "{$this->getRelatedForeignKey()}" => $entity->getId(),
                    "{$this->getForeignKey()}" => $value
                ]
            )
            ->execute();
    }
public function add(EntityAdded $event)
    {
        $entity = $event->getEntity();
        $collection = $event->getCollection();
        $this->deleteRelation($entity, $collection);

        $repository = $this->getParentRepository();
        $adapter = $repository->getAdapter();
        $value = $collection->parentEntity()->getId();

        Sql::createSql($adapter)
            ->insert($this->getRelationTable())
            ->set(
                [
                    "{$this->getRelatedForeignKey()}" => $entity->getId(),
                    "{$this->getForeignKey()}" => $value
                ]
            )
            ->execute();
    }
public function add ( EntityAdded $ event ) { $ entity = $ event -> getEntity ( ) ; $ collection = $ event -> getCollection ( ) ; $ this -> deleteRelation ( $ entity , $ collection ) ; $ repository = $ this -> getParentRepository ( ) ; $ adapter = $ repository -> getAdapter ( ) ; $ value = $ collection -> parentEntity ( ) -> getId ( ) ; Sql :: createSql ( $ adapter ) -> insert ( $ this -> getRelationTable ( ) ) -> set ( [ "{$this->getRelatedForeignKey()}" => $ entity -> getId ( ) , "{$this->getForeignKey()}" => $ value ] ) -> execute ( ) ; }
Saves the relation row upon entity add

@param EntityAdded $event
Saves the relation row upon entity add