src/ngrest/plugins/CheckboxRelation.php
protected function setRelation(array $value, $viaTableName, $localTableId, $foreignTableId, $activeRecordId)
    {
        Yii::$app->db->createCommand()->delete($viaTableName, [$localTableId => $activeRecordId])->execute();
        $batch = [];
        foreach ($value as $k => $v) {
            // $this->id: the value of the current database model, example when relation ins on user model id would be user id
            // $v['id'] extra field values foreached from the join table, so id will represent the joined table pk.

            // issue #696 array logic
            if (is_array($v)) { // its an array and is based on the logic of the angular checkbox releation ['id' => 123] // new: 'value' => 123 since beta6
                if (isset($v['value'])) {
                    $batch[] = [$activeRecordId, $v['value']];
                }
            } else { // its not an array so it could have been assigned from the frontend
                $batch[] = [$activeRecordId, $v];
            }
        }
        if (!empty($batch)) {
            Yii::$app->db->createCommand()->batchInsert($viaTableName, [$localTableId, $foreignTableId], $batch)->execute();
        }
        return true;
    }
protected function setRelation(array $value, $viaTableName, $localTableId, $foreignTableId, $activeRecordId)
    {
        Yii::$app->db->createCommand()->delete($viaTableName, [$localTableId => $activeRecordId])->execute();
        $batch = [];
        foreach ($value as $k => $v) {
            // $this->id: the value of the current database model, example when relation ins on user model id would be user id
            // $v['id'] extra field values foreached from the join table, so id will represent the joined table pk.

            // issue #696 array logic
            if (is_array($v)) { // its an array and is based on the logic of the angular checkbox releation ['id' => 123] // new: 'value' => 123 since beta6
                if (isset($v['value'])) {
                    $batch[] = [$activeRecordId, $v['value']];
                }
            } else { // its not an array so it could have been assigned from the frontend
                $batch[] = [$activeRecordId, $v];
            }
        }
        if (!empty($batch)) {
            Yii::$app->db->createCommand()->batchInsert($viaTableName, [$localTableId, $foreignTableId], $batch)->execute();
        }
        return true;
    }
protected function setRelation ( array $ value , $ viaTableName , $ localTableId , $ foreignTableId , $ activeRecordId ) { Yii :: $ app -> db -> createCommand ( ) -> delete ( $ viaTableName , [ $ localTableId => $ activeRecordId ] ) -> execute ( ) ; $ batch = [ ] ; foreach ( $ value as $ k => $ v ) { // $this->id: the value of the current database model, example when relation ins on user model id would be user id // $v['id'] extra field values foreached from the join table, so id will represent the joined table pk. // issue #696 array logic if ( is_array ( $ v ) ) { // its an array and is based on the logic of the angular checkbox releation ['id' => 123] // new: 'value' => 123 since beta6 if ( isset ( $ v [ 'value' ] ) ) { $ batch [ ] = [ $ activeRecordId , $ v [ 'value' ] ] ; } } else { // its not an array so it could have been assigned from the frontend $ batch [ ] = [ $ activeRecordId , $ v ] ; } } if ( ! empty ( $ batch ) ) { Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( $ viaTableName , [ $ localTableId , $ foreignTableId ] , $ batch ) -> execute ( ) ; } return true ; }
Set the relation data based on the configuration.

@param array $value The valued which is provided from the setter method
@param string $viaTableName Example viaTable name: news_article_tag
@param string $localTableId The name of the field inside the viaTable which represents the match against the local table, example: article_id
@param string $foreignTableId The name of the field inside the viaTable which represents the match against the foreign table, example: tag_id
@return boolean Whether updating the database was successfull or not.
Set the relation data based on the configuration .