Hi,
i have a scenario, while i am trying to save data in the database, that does not let me save the data i need.
What is happening is that i am using a framework and i am trying to integrate a new functionality. This framework has a process called enrollment during which several events/functions get triggered one by one and each one has it own model, and schema.
One of those events/procedures is called provisioning during which i am trying to store data in a table i created and which is associated to a model and a controller. The model is Vo, the table is vos and so on. I am trying to be strict with naming conventions.
I have also defined all the belongs to
and has many
relationships and i am able to access the model. I have tested it.
But what seems to be the problem is that while i am trying to access one model and add data in the database another process of the overall enrollment flow has already “taken” access to the database.
As a result when i execute $this->$model->save($save_data)
the beforeSave
event in my $model
fires but the data fetched are wrong. More specifically i get a data array with mixed columns. All the ones i added, plus some columns from the other model.
As a result, the transaction i initiated breaks and if i don’t return false
from inside beforeSave
the whole transaction fails as shown below:
Stack Trace: #0 /srv/comanage/comanage-registry-3.1.1/lib/Cake/Model/Datasource/DboSource.php(472): PDOStatement->execute(Array) #1 /srv/comanage/comanage-registry-3.1.1/lib/Cake/Model/Datasource/Database/Postgres.php(224): DboSource->_execute('SELECT DISTINCT...', Array) #2 /srv/comanage/comanage-registry-3.1.1/lib/Cake/Model/Model.php(1397): Postgres->describe(Object(CoPetitionHistoryRecord)) #3 /srv/comanage/comanage-registry-3.1.1/lib/Cake/Model/Model.php(1582): Model->schema() #4 /srv/comanage/comanage-registry-3.1.1/app/Model/CoPetitionHistoryRecord.php(91): Model->create(Array) #5 /srv/comanage/comanage-registry-3.1.1/app/Controller/CoPetitionsController.php(780): CoPetitionHistoryRecord->record('2100', 400, 'SX', 'SQLSTATE[25P02]...') #6 /srv/comanage/comanage-registry-3.1.1/app/Controller/CoPetitionsController.php(2340): CoPetitionsController->dispatch('provision', '2100') #7 [internal function]: CoPetitionsController->provision('2100') #8 /srv/comanage/comanage-registry-3.1.1/lib/Cake/Controller/Controller.php(491): ReflectionMethod->invokeArgs(Object(CoPetitionsController), Array) #9 /srv/comanage/comanage-registry-3.1.1/lib/Cake/Routing/Dispatcher.php(193): Controller->invokeAction(Object(CakeRequest)) #10 /srv/comanage/comanage-registry-3.1.1/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(CoPetitionsController), Object(CakeRequest)) #11 /srv/comanage/comanage-registry-3.1.1/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse)) #12 {main} 2018-06-24 12:04:51 Error: [MissingControllerException] Controller class CssController could not be found.
As you can see CoPetition controller returns an error while i firing the save from inside VoProvisioner, Model.
Any suggestions? I know i am missing something but i do not know what?
An ugly solution would be to process data
array inside beforeSave
in such a way that will take the correct form. At the moment i am trying to find a more fine grade solution, consistent with the MVC philosophy.
Thank you in advance!
ioigoume