Updating the wrong record????

I have an application for learning by moving throug a hierarchy of units. When learning you can go through the units in the same level ("go left-right") or go "down" to a lower level.

Two tables:

learnings (id*,fkuser, fkstartingunit, belongsto)

learningstructure (fkunit, fk_learnings, completed)

When the user goes "down" I add a new Learning that "belongs_to" the previous one. Then I get all units on the lower level and add them to the learning structure so I can move through them.

In the moment the user goes "down" I still have to make the current unit "completed" and then move on to lower level units.


Learnings (1, 99, 100, NULL)

Learnings (2, 99, 102, 1) -> this added when I want to go "down"

Learning Structure (100, 1, 1)

Learning Structure (101, 1, 1)

Learning Structure (102, 1, 0) -> here I click the link to go "down", a new Learning added and items below added

Learning Structure (103, 2, 0)

Learning Structure (104, 2, 0)


$prev_id = 1

$uid = 102

$phql = "UPDATE LearningStructure SET completed=1 WHERE fklearnings=$prevlid AND fk_unit = $uid";

$result = $this->modelsManager->executeQuery($phql);


Learning Structure (102, 1, 0) - not updated

Learning Structure (103, 2, 1) - UPDATED???



It seems that the problem for Phalcon is that I inserted the lower level items to the DB before updating this record.

When I var_dump the record before updating it, there is a property called _lastinitialized that has the values of the next row in the DB (103,2).

After the update this (wrong) record is updated (as shown above), instead of the one that should be updated.



Hi, that's strange indeed. Could you show the full action's code ?


I had to do the update of the record (102,1) first, then add the other rows after. That solved the problem. Still no clue why this happens. I'll post the code in next reply.