E
E
Ernest Faizullin2016-04-28 20:00:47
PHP
Ernest Faizullin, 2016-04-28 20:00:47

How to correctly insert a row into a table that has multiple primary keys?

There is zend framework 1.12 and a model in which an array with three keys is used as a primary key

class Admin_Model_DbTable_Starring extends My_Db_Table
{
    protected $_name = 'starring';

    protected $_primary = array('play_id', 'person_id', 'role_id'); // если тут не массив, а строка с 1 ключом, то все норм
    protected $_rowClass = 'My_Db_Table_Row';
    public $prefix  = 'str';

    ...

A row is inserted into the table in this way (all parameters come as numbers, I checked):
$starringModel = new Admin_Model_DbTable_Starring();

    $row = $starringModel->createRow();
    $row->play_id = $play_id;
    $row->person_id = $person_id;
    $row->role_id = $role_id;
    $row->status = 2;

    $row->save();

The record is created normally, but after insertion, the server response throws out Notice Array to string conversion in /var/www/html/library/Zend/Db/Statement/Pdo.php on line 228
Such nonsense only with tables where there is more than 1 primary key : $_primary = array('play_id', 'person_id', 'role_id'). Where there is exactly 1 key and it is equal to the string, for example $_primary = 'play_id' everything is fine.
How to get rid of this Notice? Has anyone experienced this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2016-04-28
@erniesto77

There cannot be more than one primary key.
Actually, it can't.
There can only be one primary key.
But the primary key can be composite.
Judging by the characteristic php E_NOTICE, in zend fw the composite primary key is specified in some other way, because the code tries to cast $_primary to a string and receives E_NOTICE for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question