Hi all,
I have a table with the following schema in MySQL:
CREATE TABLE snmp_trap (
snmp_trap_id INTEGER AUTO_INCREMENT,
recv_date DATE NOT NULL, -- just for partitioning only
recv_time DATETIME NOT NULL,
trap_oid CHAR(100) NOT NULL,
-- recv_date is included as partition key has to be
-- included in any 'unique' key, including primary key
PRIMARY KEY(snmp_trap_id, recv_date)
) ENGINE = MyISAM
PARTITION BY HASH (TODAYS(recv_date))
PARTITIONS 1024;
and created a model ‘SnmpTrap’ using gii.
The problem is that the primary key I really want is just ‘snmp_trap_id’ not
(snmp_trap_id, recv_date) guessed by Yii. By following the advice in overriding primary key, which suggest adding the following to ‘SnmpTrap’ model:
public function init()
{
$this->getMetaData()->tableSchema->primaryKey = 'snmp_trap_id';
}
I can have an array of active record with correct primary key. But when calling
SnmpTrap::model()->findByPk(some_pk), it return errors. It seems that the init()
function is skipped when calling the class method SnmpTrap::model(). What should I
do?
Thanks in advance.