I have tables that are created on the fly and I'd like to access it thru Model. Since those tables are dynamically created, I don't have the model .php files for them. The tables are created conforming to Cake's naming convention. I tried to use loadModel() to load them but Cake still complains that the tables are missing.
Is there a solution for it?
Thank you.
As of this writing, using CakePHP 2.1.2
In your controller add App::uses('AppModel', 'Model');
. Then instantiate the model
$RemoteHeader = new AppModel(array(
'table' => 'SOP10100',
'ds' => 'external',
'name' => 'RemoteHeader',
'alias' => 'InvoiceHeader',
'primaryKey' => 'id',
'hasMany' => array(
'InvoiceDetail' => array(
'foreignKey' => 'SOPNUMBE',
'counterCache' => false
))));
then fetch the data with any Model parameters you need:
$data = $RemoteHeader->find('all', array(
'fields' => array(
'SOPNUMBE',
'CUSTNAME',
'DUEDATE',
'DOCDATE',
'DOCAMNT',
'SUBTOTAL')));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With