3

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 on debug to level two shows that the temporary table is success fully created but for some reason, when I try and load it as a model it doesn't work. It looks like cake doesn't even try to see if the table exists as there is no "SHOW FULL COLUMNS FROM ...' query being displayed. Not sure how to force cake to check for its existence.

$tmpModel = 'tempModel';
$tmpTable = 'temp_models';

$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
$this->loadModel($tmpModel);

Thanks in advance.

  • maybe "CREATE TEMPORARY TABLE"?! – Igor Apr 15 '11 at 10:15
  • Thanks, that was a typo as I was trying normal tables to see if they would work in this way. (They don't) –  Apr 15 '11 at 10:21
  • Could you modify your question that it would sensible for one who will check it still some time. In a sense what was exactly a problem and the solution below. Thanks. – Igor Apr 15 '11 at 10:34

3 Answers3

6

$tmpModel = 'TempModel'; // CamelCase

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

final issue may be cache. but dont think so

dogmatic69
  • 7,574
  • 4
  • 31
  • 49
  • Thanks, these are the kind of things that once you know it saves so much time. –  Apr 15 '11 at 11:21
3

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

2

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/

Dipu
  • 21
  • 3
  • 2
    Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Spontifixus Dec 05 '12 at 18:15