Complex SQL query is required in order to retrieve some custome data set. Resulting data contain 2 diffrent models properties - Document and Job. Now there is problem of converting (and splitting) this primitive arrays data into model objects.
Execute SQL query (at self::QUEUE_QUERY)
$pdoResults = $db->query(self::QUEUE_QUERY); $pdoResults->setFetchMode(PDO::FETCH_ASSOC); $data = $pdoResults->fetchAll();
Then populate model object with the array
$this->document = new Document(); $this->document->assign($data); $this->job = new Job(); $this->job->assign($data);
Each model pick items coresponding with properties. Now it might looks ok, but it's not.
Model is not aware of the fact that is existing record. When Im trying to performe save() then he trying to insert new record (what causing primary key violation).
How I can bind model with data populated on my own with certain already existing records in database?
I would like to model performe an update when Im call save on it.