-1
我有一個有三個關係的數據庫。 cheque->帳戶 - >客戶。現在我試圖使用以下方法同時從全部三個表中檢索數據。YII來自第三個表格的關係數據
$query = Cheque::find();
$query->joinWith(['account.customer']);
$query->orderBy('sr desc');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
檢查型號:
class Cheque extends \common\components\db\ActiveRecord {
/**
* @inheritdoc
*/
public static function tableName() {
return 'cheque';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['sr'], 'integer'],
[['ID', 'account_ID'], 'required'],
[['ID', 'account_ID', 'created_by', 'branch_ID', 'application_ID'], 'string'],
[['serial_start', 'serial_end', 'status'], 'number'],
[['created_on'], 'safe']
];
}
/**
* @inheritdoc
*/
public function attributeLabels() {
return [
'ID' => 'ID',
'account_ID' => 'Account ID',
'serial_start' => 'Serial Start',
'serial_end' => 'Serial End',
'created_on' => 'Created On',
'created_by' => 'Created By',
'branch_ID' => 'Branch ID',
'application_ID' => 'Application ID',
'status' => 'Status',
'sr' => 'ID'
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAccount() {
return $this->hasOne(Account::className(), ['ID' => 'account_ID']);
}
public static function getActiveChequeBook($account_ID) {
return Cheque::findAll(['account_ID' => $account_ID, 'status' => array_search('Active', \common\models\Lookup::$cheque_status)]);
}
}
但在執行這一點,我得到以下錯誤: 預>異常'警予\基地\ InvalidCallException '有消息'設置只讀屬性:通用\ models \ Account :: customer '
更新答案,並顯示帳戶。客戶關係請 – scaisEdge
顯示您的支票模型 – scaisEdge
@scaisEdge現在看看它 –