我在这个查询中工作。
$data = RtvReqDet::find()
->joinWith(['header', 'rtvCard.serial sn', 'rtvCard.serial.item si', 'rtvCard.item ri' ])
->select([
'header.requested_by as classification',
'ifnull(sn.no, rtvCard.serial_no) AS serial',
'ifnull(si.no, ri.no) AS item',
'ifnull(si.uom, ri.uom) AS uom',
'COUNT(ifnull(sn.no, rtvCard.serial_no)) AS qty',
])
->where(['rtv_spare_parts_requisition_id' => $record->id ])
->groupBy(['serial'])->all();
它在Windows上工作。但是没有在Linux上工作并且出现这个错误:
Exception 'yii\base\InvalidParamException' with message 'app\models\RtvCard has no relation named "serial AS sn".'
我试着用Linux完全降低我的php版本和mysql版本。但我仍然可以在我的窗户上进行交易。所以它与php和mysql版本没有任何冲突。你认为这有什么不对?
这是rtvCard模型。这是我以前和我合作过的同事定制的。我在本次讨论中删除了一些我认为不需要的关系。
<?php
namespace app\models;
use app\components\ActiveRecord;
use app\components\FieldException;
use yii\base\Exception;
class RtvCard extends ActiveRecord {
static function tableName() {
return "rtv_card";
}
static function objectName() {
return "rtv card";
}
// RELATIONS
function getCustomer() {
return $this->hasOne(Customer::className(), [ "id" => "customer_id" ])->from([ "customer" => Customer::tableName() ]);
}
function getSerial() {
return $this->hasOne(SerialNumbers::className(), [ "id" => "serial_id" ])->from([ "serial" => SerialNumbers::tableName() ]);
}
function getItem() {
return $this->hasOne(Items::className(), [ "id" => "item_id" ])->from([ "item" => Items::tableName() ]);
}
function getTransfer() {
return $this->hasOne(RtvTransferDetail::className(), [ "rtv_card_id" => "id" ])->from([ "transfer" => RtvTransferDetail::tableName() ]);
}
// USED FOR ERROR MESSAGES
static $attributeLabels = [
"id" => "ID",
"no" => "RTV No",
"item_id" => "Item",
"serial_id" => "Serial no.",
"defect_id" => "Defect",
"description" => "Complaints",
"date_received" => "Date received",
"received_by" => "Received by",
"customer_id" => "Dealer",
"reference_no" => "Reference no.",
"tag" => "Tag",
"technician_id" => "Technician",
"warehouse" => "Warehouse",
];
// FIELD NAMES IN VIEW IF NOT THE SAME WITH ATTRIBUTE
// USE STATIC::GET-FIELD($ATTRIBUTE-NAME)
// ATTRIBUTE NAME SHOULD BE THE TABLE ATTRIBUTES ITSELF ( NOT THE FIELD NAME IN VIEWS )
// ATTRIBUTE NAME => FIELD NAME
static $attributeFields = [
"item_id" => "item",
"serial_id" => "serial",
"defect_id" => "defect",
"customer_id" => "dealer",
"received_by" => "received-by",
"date_received" => "received-date",
"reference_no" => "reference-no",
"open_serial_id_no" => "no",
"open_serial_id_item" => "item",
"technician_id" => "technician",
];
答案 0 :(得分:1)
从Yii 2.0.7开始,关系别名的快捷方式是'rtvCard.serial sn'
而不是(来自Bizley的评论{{1也有效)'rtvCard.serial AS sn'
来自docs:
如果在连接嵌套关系时需要中间表的别名,例如
AS
,您需要嵌套$query->joinWith(['orders.product'])
次调用,如下例所示:joinWith
所以在你的情况下:
$query->joinWith(['orders o' => function($q) {
$q->joinWith('product p');
}])
->where('o.amount > 100');
答案 1 :(得分:1)
在两个安装中你的版本都相同是更好的...但是请确保你的文件正确适用于UpperCase ..
RtvCard.php
..因为Windows文件名不区分大小写,但linux是区分大小写的。 还要检查控制器中的use classname .....请参阅正确的区分大小写的名称