Using AR for temporary tables

Hi All,

I need to make a temporary table (MySQL) to crunch some data then delete the table in one movement. I therefore need/would like to create a model extends CActiveRecord that can work with this table. Now as the table name will change for each call (it’s based on a user dependant variable) I need to specify the table name to the model dynamically. Can this be done?

In case you need some more background on why I am doing this it is due to working with a MSSQL db as well as a MySQL db. The data (rent transactions) will be taken from the MSSQL db, crunched, dumped to the temporary MySQL db, then back out again for further processing. The table name will vary as it will be based on the logged in user who is doing it as to avoid table name collisions.

U can create dynamic ARModel

any tips on how to do this?

See CActiveRecord::tableName(). You can override this method to provide a random table name.

Or you could use one table… with additional field userid to separate different users…

funilly enough that’s exactly how I am approaching it this morning.

Thanks anyway.

This thread is a bit old, but just overriding the tableName method does not seem to do the trick. I also tried with a construct that took a parameter and changed a private property to a temporary name which was in turn returned by tableName.

It did not work either.

I ended up extending into another class and changing the tableName method there - that worked.

you have to modify the name and the rowname of tableschema metadata


[model istance]->metaData->name = [table name];

[model istance]->metaData->rawName = [table name];