Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How i can delete register with composite primary key?

I had a table with two primary keys wich are foreing keys

Table "app_keyword"

    id_app_fk //reference table app -> id_app
    id_lang_fk  //reference table lang -> id_lang

I canĀ“t delete a register of table, i tried many methods but nothing works

    //not work
    $keyword_del =  $keyword = AppKeyword::find(
            'conditions'    =>  'id_app_fk_app = :id_app: AND id_lang_fk = :id_lang:',
            'bind'          =>  array('id_app' => 5, 'id_lang' => 1)

    //not work  
    $phql = "DELETE FROM AppKeyword 
    WHERE id_app_fk = :id_app: 
    AND id_lang_available_fk = :id_lang:";
    $this->modelsManager->executeQuery($phql, array('id_app' => 5, 'id_lang' => 1));

    //not work
    $keyword = AppKeyword::find(
                    'conditions'    =>  'id_app_fk = :id_app: and id_lang_fk = :id_lang:',
                    'bind'              =>  array('id_app' => 5, 'id_lang' => 1)

Allways display this message: A primary key must be defined in the model in order to perform the operation

How i can solve this?

Check to see if the table you setSource to in your model has a column as primary key.

edited Sep '15

Well, the error it was being caused for a error in database design, the primary key was not created as it should. But now i removed the composite primary key and i created a single id for the table, and this solved the problem.

Now works perfectly.