Create temporary table in CakePHP and load it as a Model

前端 未结 3 1208
不思量自难忘°
不思量自难忘° 2020-12-11 09:54

My plan is to create a temporary table using the $this->Model->query(); method then load it as a Model but I\'m getting an error staying \"Missing Database Table\". Turning

相关标签:
3条回答
  • 2020-12-11 10:28

    After doing google for an hour .. finally found a way to have Model on Temporary table and it works like a charm http://web2.0goodies.com/blog/uncategorized/mysql-temporary-tables-and-cakephp-1-3/

    0 讨论(0)
  • 2020-12-11 10:33

    Ok, after looking around a bit I have found a solution that works. The problem was that Cake had already loaded the models caches at page load so used them as reference to the existence of a table. To resolve this problem I used "App::import('Model', $tmpModel);" which created the new modelCache allowing the loadModel script to run successfully.

    $tmpModel = 'tempModel';
    $tmpTable = 'temp_models';
    
    $this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
    App::import('Model', $tmpModel);
    $this->loadModel($tmpModel);
    

    Thanks anyway

    0 讨论(0)
  • 2020-12-11 10:41

    $tmpModel = 'TempModel'; // CamelCase

    also try, ClassRegisty::init($tmpModel);

    final issue may be cache. but dont think so

    0 讨论(0)
提交回复
热议问题