Hi there,
I’m new with Yii and I’m trying to learn it.
I’ve a problem with relations transaction_stat as defined below.
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'address' => array(self::HAS_MANY, 'Address', 'userFK'),
'transaction' => array(self::HAS_MANY, 'Transaction', 'userFK'),
'transaction_stat' => array(self::STAT, 'Transaction', 'userFK',
'select' => 'SUM(importo) as fatturato, count(*) as transazioni, MAX(data) as ultimo_acquisto',
),
);
}
This relations give me an exception because Yii create the query in this way:
SELECT userFK
AS c
, SUM(importo) as fatturato, count(*) as transazioni, MAX(data) as ultimo_acquisto AS s
So it add an AS s
at my last element that broke the query.
If I try so set relation in this way as explained in CActiveRecord api page
(Additional options may be specified as name-value pairs in the rest array elements:
‘select’: string|array, a list of columns to be selected):
'select' => array('SUM(importo) as fatturato', 'count(*) as transazioni', 'MAX(data) as ultimo_acquisto'),
I’ve this exception “Column not found: 1054 Unknown column ‘Array’ in ‘field list’. The SQL statement executed was: SELECT userFK
AS c
, Array AS s
FROM”
At the moment i’m not able to solve this.
Could someone help me?
Thanks in advance