2017-01-20 1 views
0

yii2에 문제가있어서 도움이 필요합니다. 저는 MsSQL db1과 db2에 2 개의 데이터베이스를 가지고 있는데, db2에는 db1 테이블에 대한 뷰가 있습니다. 문제는 내가 db2에 삽입 할 때 $ model-> id 또는 $ model-> getPrimaryKey()를 사용하여 트랜잭션 ID를 가져올 수 없다는 것입니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까? 이 내 모델 : 많은 조사와 yii2의 소스 코드의 수정 후다른 db 테이블의 뷰에 삽입

<?php 

namespace app\models; 

use Yii; 

class Documents extends \yii\db\ActiveRecord 
{ 
    public static function primaryKey() 
    { 
     return ['id']; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public static function tableName() 
    { 
     return 'documents'; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function rules() 
    { 
     return [ 
      [['realname', 'size'], 'required'], 
      [['realname'], 'string'], 
      [['size'], 'integer'], 
     ]; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function attributeLabels() 
    { 
     return [ 
      'id' => 'ID', 
      'realname' => 'Realname', 
      'size' => 'Size', 
     ]; 
    } 


    /** 
    * @return \yii\db\ActiveQuery 
    */ 
    public function getDocumentSchoolRegistrationToInsurances() 
    { 
     return $this->hasMany(DocumentSchoolRegistrationToInsurance::className(), ['document' => 'id']); 
    } 

    /** 
    * @return \yii\db\ActiveQuery 
    */ 
    public function getDocumentSchoolregistrations() 
    { 
     return $this->hasMany(DocumentSchoolregistration::className(), ['document' => 'id']); 
    } 

} 
+0

당신이 시도한 것은 무엇입니까? –

+0

$ model-> id 및 $ model-> PrimaryKey() – Yordankis

답변

1

, 나는 기본 키가 autoincremental이 경우 save() 사용 후 YII는 레지스트리의 값을 다시로드 실현에있는 내 사건은 결코 성취되지 않을 것이다.
보기이기 때문에 save() 메서드를 사용한 후 Yii :: $ app-> db-> lastInsertID 메서드를 사용하여 삽입에서 생성 된 ID를 가져 오는 것이 해결책입니다.
새로 만든 레지스트리로드를 강제로 수행하는 것이 유용 할 것이라고 생각합니다.

관련 문제