Wrong result when retrieving old data after an update

#1

Hi all,
I’m new to Cake and maybe this is just a dumb question.

Inside a component I’m creating an entity, updating its values and getting it back again from the db (it’s just a test that I’m performing to understand the framework).

Here’s the code:

$contact_form = $this->contact_forms->get(1);

$this->assertTrue(! empty($contact_form));
$this->assertEquals('Contacts', $contact_form->get('header_text'));

$contact_form->set('header_text', 'New header text');
$this->contact_forms->save($contact_form);

$contact_form = $this->contact_forms->get(1);
$this->assertEquals('New header text', $contact_form->get('header_text'));

The problem is that, the last test fails because ‘header_text’ is still ‘Contacts’. The db is updated correctly: I can see the new values in the correct place. The $contact_form contains a original field with the correct data $original[‘header_text’] => ‘New header text’.

I’m not caching anything (unless Cake is doing it by default). What am I doing wrong ?

0 Likes

#2

By the way, I’ve enabled Datasource logging for test environment and the query is correctly logged and executed. The result of the query has, as expected, the correct fields in it while the retrieved entity has the wrong fields.

0 Likes