We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

possible bug with \Mvc\Model's "useDynamicUpdate" (v2.0.4)

After updating to 2.0.4 I get the following error (per every attribute in the model) when selecting a model from the database:

Notice: Cannot use a scalar value as an array in phalcon/mvc/model.zep on line 3600

This only happens when I set useDynamicUpdate = true. Is this a bug?



5.7k
edited Jul '15

After looking at the code in GitHub, line 3600 is within the "public function setSnapshotData" function. That is why you're seeing the issue only when you have useDynamicUpdate = true

https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model.zep#L3562

However, that doesn't mean that "useDynamicUpdate" function is necessarily the issue.

Can you post up your PHP code for the model that is having the issue?

I briefly skimmed the Zephir docs to better understand what the setSnapshotData() function was doing at the time of the error. If for some reason there is an issue with your model, hopefully it'll be enough to help you track it down.

I reduced the model to

class User extends \Phalcon\Mvc\Model
{
    public function initialize()
    {
        $this->useDynamicUpdate(true);
    }
}

and the controller is

$user = \User::findFirst(1);

and am still getting the error. By the way I'm on Windows 8 localhost (xampp - php 5.6.8).

As an aside, does dynamic update require snapshots to be on? I set keepSnapshots=true but it didn't help.



5.7k
edited Jul '15

Assuming that your User model has a field called "user_id" as the primary key, what happens if you try the following:


$user = \User::findFirstByUserId(1); // If you are searching on "id" instad of "user_id" replace with findFirstById(1)

if(!$user){
exit("User does not exist");
}

The first time I used User::findFirst($pk_value); I had an issue with it so I always call the specific field using Model::findFirstByFieldName($pk_value) and it has solved numerous issues I ran into.

Also, do you define your column map in the model? https://docs.phalcon.io/en/latest/reference/models.html#independent-column-mapping

If you don't use independent column mapping, I would recommend doing so. And if you don't already, you should look into Phalcon's DevTools as well. Invaluable tool for getting things up and running quickly and accurately

I tried that but to no avail. Also, thanks for the other advice.

The code I posted above is perfectly fine but started acting up after the last version update. Is there a bug in 2.0.4 or did something change that I should know about?



5.7k

Are you able to post the actual code you use? The code does look valid but it is just a small part of your overall codeset I'm sure. I'm just trying to get enough info to help debug either in the app or the framework itself. It would be great to see enough to hopefully reproduce the issue on my side

I tried that but to no avail. Also, thanks for the other advice.

The code I posted above is perfectly fine but started acting up after the last version update. Is there a bug in 2.0.4 or did something change that I should know about?

edited Jul '15

By the way do you have error reporting enabled?

error_reporting(E_ALL);
ini_set('display_errors', 1);

I'm pretty sure the reason for this issue is because the setSnapshotData function is missing the below code

let attribute = [];

OR they should put a variable in the snapshot array instead of attribute[0]



2.5k
Accepted
answer
edited Jul '15

This is a bug and is set to be fixed. https://github.com/phalcon/cphalcon/issues/10648