2016-08-19 3 views
1

NRP에서 검색을 시도 할 때 오류가 발생했습니다. 여기 모델의 코드SQLSTATE [23000] : 무결성 제약 조건 위반 : 1052 where 절에 'NRP'열이 불분명 함

<?php 

namespace app\models; 

use Yii; 
use yii\base\Model; 
use yii\data\ActiveDataProvider; 
use app\models\AlumnyS2; 
use app\models\AlumniIntegrasi; 

/** 
* AlumnyS2Search represents the model behind the search form about `app\models\AlumnyS2`. 
*/ 
class AlumnyS2Search extends AlumnyS2 
{ 
    /** 
    * @inheritdoc 
    */ 
    public function rules() 
    { 
     return [ 
      [['Alumnys2ID'], 'integer'], 
      [['NRP', 'namaMahasiswaText', 'ProgramStudi', 'Tanggal_Masuk', 'Tanggal_Lulus'], 'safe'], 
     ]; 
    } 

    public $NamaMahasiswa; 
    public $namaMahasiswaText; 

    /** 
    * @inheritdoc 
    */ 
    public function scenarios() 
    { 
     // bypass scenarios() implementation in the parent class 
     return Model::scenarios(); 
    } 

    /** 
    * Creates data provider instance with search query applied 
    * 
    * @param array $params 
    * 
    * @return ActiveDataProvider 
    */ 
    public function search($params) 
    { 
     $query = AlumnyS2::find(); 
     $query->joinWith('alumniIntegrasi'); 
     // add conditions that should always apply here 

     $dataProvider = new ActiveDataProvider([ 
      'query' => $query, 
     ]); 

     $this->load($params); 

     if (!$this->validate()) { 
      // uncomment the following line if you do not want to return any records when validation fails 
      // $query->where('0=1'); 
      return $dataProvider; 
     } 



     // grid filtering conditions 
     $query->andFilterWhere([ 
      'Alumnys2ID' => $this->Alumnys2ID, 
     ]); 

     $query->andFilterWhere(['like', 'NRP', $this->NRP]) 
      ->andFilterWhere(['like', 'alumniIntegrasi.NamaMahasiswa', $this->namaMahasiswaText]) 
      ->andFilterWhere(['like', 'ProgramStudi', $this->ProgramStudi]) 
      ->andFilterWhere(['like', 'Tanggal_Masuk', $this->Tanggal_Masuk]) 
      ->andFilterWhere(['like', 'Tanggal_Lulus', $this->Tanggal_Lulus]); 

     return $dataProvider; 
    } 
} 

과 : 여기

<?php 

namespace app\models; 

use Yii; 

/** 
* This is the model class for table "alumnys2". 
* 
* @property integer $Alumnys2ID 
* @property string $NRP 
* @property string $ProgramStudi 
* @property string $Tanggal_Masuk 
* @property string $Tanggal_Lulus 
* 
* @property AlumniIntegrasi $nRP 
*/ 
class AlumnyS2 extends \yii\db\ActiveRecord 
{ 
    /** 
    * @inheritdoc 
    */ 
    public static function tableName() 
    { 
     return 'alumnys2'; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function rules() 
    { 
     return [ 
      [['NRP'], 'required'], 
      [['NRP'], 'string', 'max' => 15], 
      [['ProgramStudi'], 'string', 'max' => 5], 
      [['Tanggal_Masuk', 'Tanggal_Lulus'], 'string', 'max' => 30], 
      [['NRP'], 'exist', 'skipOnError' => true, 'targetClass' => AlumniIntegrasi::className(), 'targetAttribute' => ['NRP' => 'NRP']], 
     ]; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function attributeLabels() 
    { 
     return [ 
      'Alumnys2ID' => Yii::t('app', 'Alumnys2 ID'), 
      'NRP' => Yii::t('app', 'Nrp'), 
      'ProgramStudi' => Yii::t('app', 'Program Studi'), 
      'Tanggal_Masuk' => Yii::t('app', 'Tanggal Masuk'), 
      'Tanggal_Lulus' => Yii::t('app', 'Tanggal Lulus'), 
      'namaMahasiswaText' => Yii::t('app', 'Nama Mahasiswa'), 
     ]; 
    } 

    /** 
    * @return \yii\db\ActiveQuery 
    */ 
    public function getalumniIntegrasi() 
    { 
     return $this->hasOne(alumniIntegrasi::className(), ['NRP' => 'NRP']); 
    } 

    public function getNamaMahasiswaText() 
    { 
     $alumniIntegrasi = alumniIntegrasi::findOne(['NRP'=> $this->NRP]); 
     if (empty($alumniIntegrasi)) 
      return ''; 
     return $alumniIntegrasi->NamaMahasiswa; 
    } 

} 

및 modelsearch 코드입니다 그것은 ": 무결성 제약 조건 위반 1052 열 조항이 모호 곳에서 'NRP'는 SQLSTATE가 [23000]가"말했다 다음은 색인입니다 :

<?php 

use yii\helpers\Html; 
use yii\grid\GridView; 
use app\models\AlumniIntegrasi; 

/* @var $this yii\web\View */ 
/* @var $searchModel app\models\AlumnyS2Search */ 
/* @var $dataProvider yii\data\ActiveDataProvider */ 

$this->title = Yii::t('app', 'Alumny S2s'); 
$this->params['breadcrumbs'][] = $this->title; 
?> 
<div class="alumny-s2-index"> 

    <h1><?= Html::encode($this->title) ?></h1> 
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?> 

    <p> 
     <?= Html::a(Yii::t('app', 'Create Alumny S2'), ['create'], ['class' => 'btn btn-success']) ?> 
    </p> 
    <?= GridView::widget([ 
     'dataProvider' => $dataProvider, 
     'filterModel' => $searchModel, 
     'columns' => [ 
      ['class' => 'yii\grid\SerialColumn'], 

      //'Alumnys2ID', 
      'NRP', 
      'namaMahasiswaText', 
      'ProgramStudi', 
      'Tanggal_Masuk', 
      'Tanggal_Lulus', 

      ['class' => 'yii\grid\ActionColumn'], 
     ], 
    ]); ?> 
</div> 

그 문제를 해결하는 방법을 모릅니다. 누군가이 코드를 해결하도록 도와주세요.

$query->andFilterWhere(['like', 'alumnys2.NRP', $this->NRP]) 
      ->andFilterWhere(['like', 'alumniIntegrasi.NamaMahasiswa', $this->namaMahasiswaText]) 
      ->andFilterWhere(['like', 'alumnys2.ProgramStudi', $this->ProgramStudi]) 
      ->andFilterWhere(['like', 'alumnys2.Tanggal_Masuk', $this->Tanggal_Masuk]) 
      ->andFilterWhere(['like', 'alumnys2.Tanggal_Lulus', $this->Tanggal_Lulus]); 
+0

사용 별칭을 변경 : 감사합니다 너무 많은

내 문제는 FIXED 내가 이렇게 될 쿼리 코드를 변경한다. 체크 아웃이 링크 .. https://github.com/yiisoft/yii2/issues/2377 –

+0

비제이, 위의 코드를 기반으로 예제를 제공해 주시겠습니까? –

+0

내 문제가 해결되었습니다. 나는 쿼리 코드를이 쿼리와 같이 필터링한다. ([ 'like', 'alumnys2.NRP', $ this-> NRP]) -> andFilterWhere ([ 'like', 'alumniIntegrasi.NamaMahasiswa', $ (''like ','alumnys2.ProgramStudi ', $ this-> ProgramStudi)) -> andFilterWhere (['like ','alumnys2.Tanggal_Masuk ', $ this-> Tanggal_Masuk ]) -> andFilterWhere ([ 'like', 'alumnys2.Tanggal_Lulus', $ this-> Tanggal_Lulus]); –

답변

0

을 yor searchmodel 쿼리 필터 쿼리를

$query->andFilterWhere([ 
       'tbl_Yourtablename.NRP' => $this->NRP, 
       'tbl_Yourtablename.namaMahasiswaText' => $this->namaMahasiswaText, 
       'tbl_Yourtablename.ProgramStudi' => $this->ProgramStudi, 
       'tbl_Yourtablename.Tanggal_Masuk' => $this->Tanggal_Masuk, 
       'tbl_Yourtablename.Tanggal_Lulus' => $this->Tanggal_Lulus 

      ]); 
+0

너무 많이 Vijay. 내 문제를 해결 했어. 그것은 작동합니다. GBU :) –

+0

안녕하세요 비제이, 당신이 준 코드를 시도했을 때 NRP를 검색 할 수는 있지만 "NamaMahasiswa"는 검색 할 수 없습니다. 어떻게해야합니까?이 코드를 시도했습니다 $ query-> andFilterWhere ([ ' alumnys3.NRP '=> $ this-> NRP, 'alumniintegrasi.NamaMahasiswaText '=> $ this-> NamaMahasiswaText, 'alumnys3.ProgramStudi '=> $ this-> ProgramStudi, 'alumnys3.TanggalMasuk '=> $ this -> TanggalMasuk, 'alumnys3.TanggaKeluar'=> $ this-> TanggalKeluar –

+0

-> andFilterWhere ([, 'alumniIntegrasi.namaMahasiswaText', $ this- '처럼'> namaMahasiswaText은),이 다행 –

관련 문제