protected function insertBelongsToMany($recordName, Relation $relation, $columnValue)
    {
        $joinTable = $relation->getTable();
        $this->tables[] = $joinTable;
        $relatedRecords = explode(',', str_replace(', ', ',', $columnValue));

        foreach ($relatedRecords as $relatedRecord) {
            list($fields, $values) = $this->buildBelongsToManyRecord($recordName, $relation, $relatedRecord);
            $placeholders = rtrim(str_repeat('?, ', count($values)), ', ');
            $sql = "INSERT INTO $joinTable ($fields) VALUES ($placeholders)";
            $sth = $this->db->prepare($sql);
            $sth->execute($values);
        }
    }
protected function insertBelongsToMany($recordName, Relation $relation, $columnValue)
    {
        $joinTable = $relation->getTable();
        $this->tables[] = $joinTable;
        $relatedRecords = explode(',', str_replace(', ', ',', $columnValue));

        foreach ($relatedRecords as $relatedRecord) {
            list($fields, $values) = $this->buildBelongsToManyRecord($recordName, $relation, $relatedRecord);
            $placeholders = rtrim(str_repeat('?, ', count($values)), ', ');
            $sql = "INSERT INTO $joinTable ($fields) VALUES ($placeholders)";
            $sth = $this->db->prepare($sql);
            $sth->execute($values);
        }
    }
protected function insertBelongsToMany ( $ recordName , Relation $ relation , $ columnValue ) { $ joinTable = $ relation -> getTable ( ) ; $ this -> tables [ ] = $ joinTable ; $ relatedRecords = explode ( ',' , str_replace ( ', ' , ',' , $ columnValue ) ) ; foreach ( $ relatedRecords as $ relatedRecord ) { list ( $ fields , $ values ) = $ this -> buildBelongsToManyRecord ( $ recordName , $ relation , $ relatedRecord ) ; $ placeholders = rtrim ( str_repeat ( '?, ' , count ( $ values ) ) , ', ' ) ; $ sql = "INSERT INTO $joinTable ($fields) VALUES ($placeholders)" ; $ sth = $ this -> db -> prepare ( $ sql ) ; $ sth -> execute ( $ values ) ; } }
Insert a belongsToMany foreign key relationship.

@param  string recordName
@param  Relation $relation
@param  int $columnValue
@return void
Insert a belongsToMany foreign key relationship .