Hi all. I've got a "create" action instead of update trying iterate an updatable view:
CREATE or replace VIEW wide_exchange_rates AS
SELECT R.id, R.source_currency_name, C.real_currency AS source_real,
R.target_currency_name, D.real_currency AS target_real, R.rate, R.refresh_date
FROM `exchange_rates` AS R
LEFT JOIN currencies AS C ON (R.source_currency_name = C.name)
LEFT JOIN currencies AS D ON (R.target_currency_name = D.name)
And neither model operations nor modelManager dont work as I want:
$concurrentPairs = WideExchangeRates::find();
foreach ($concurrentPairs as $pair) {
if ($pair->source_real == $pair->target_real) {
$pair->rate = 1;
$pair->update();
}
throws exception:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1471 The target table wide_exchange_rates of the INSERT is not insertable-into' in tasks/CurrenciesTask.php:75
Stack trace:
#0 [internal function]: PDOStatement->execute()
#1 [internal function]: Phalcon\Db\Adapter\Pdo->executePrepared(Object(PDOStatement), Array, Array)
#2 [internal function]: Phalcon\Db\Adapter\Pdo->execute('INSERT INTO `wi...', Array, Array)
#3 [internal function]: Phalcon\Db\Adapter->insert('wide_exchange_r...', Array, Array, Array)
#4 [internal function]: Phalcon\Mvc\Model->_doLowInsert(Object(Phalcon\Mvc\Model\MetaData\Memory), Object(Phalcon\Db\Adapter\Pdo\Mysql), 'wide_exchange_r...', false)
#5 [internal function]: Phalcon\Mvc\Model->save()
#6 ... tasks/CurrenciesTask.php(75): Phalcon\Mvc\Model->update()
#7 [internal function]: CurrenciesTask->loadRateAction()
The same I've got with modelsManager:
$this->modelsManager->executeQuery("update WideExchangeRates set rate = 1 where source_real = target_real");
Obviously, Phalcon tries to insert record, even the update method is used directly. But why? I didn't overwrite any standart Model methods..