Custom query in model

In my model I have a "afterCreate()". Within "afterCreate()" I would like to execute a simple custom query that will insert a record into another table with the foreign key of the record just created.

If you could provide an example of how to do this with a custom query (ie no association to model) and also using Phalcon to save (ie there is an association).

Thank you in advance for the help.



37.8k

Hey man

You can use modelManager in Phalcon

     $phql = "UPDATE Phalcontip\ModelsJob SET Phalcontip\Models\Job.status = ?0 WHERE Phalcontip\Models\Job.id = ?1";
            $result = $this->modelsManager->executeQuery($phql, array(
                0 => Job::STATUS_DISPLAY,
                1 => $idJob
            ));


390

I wound up running this and it worked.

public function afterCreate()
{
    //Save 
    $data = new Motors();
    $data->save(array(
        "car_id" => $this->id,
        "identifier" => 1
    ));

}


390

Thiện I will look into your response. Thank You!