Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0.13] "Phalcon\Mvc\Model\Resultset\Simple" can not be iterated after "setHydrateMode()" #11973

Closed
guweigang opened this issue Jul 14, 2016 · 8 comments
Assignees
Labels
bug A bug report status: medium Medium
Milestone

Comments

@guweigang
Copy link
Contributor

guweigang commented Jul 14, 2016

If I use mode HYDRATE_ARRAYS ...

        $r = BookModel::find();
        $r->setHydrateMode(\Phalcon\Mvc\Model\Resultset::HYDRATE_ARRAYS);

        foreach($r as $i) {  // this is line 52
            echo $i['name'];
        }

... I will get errors like:

Warning: Illegal offset type in /Users/guweigang/github/bullsoft/fmyuedu/backend/app/services/BookService.php on line 52

If i use mode HYDRATE_OBJECTS ...

        $r = BookModel::find();
        $r->setHydrateMode(\Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS);

        foreach($r as $i) {  // this is line 52
            echo $i->name;
        }

... I will get errors like:

Warning: Phalcon\Mvc\Model::cloneResultMapHydrate(): Property should be string in /Users/guweigang/github/bullsoft/fmyuedu/backend/app/services/BookService.php on line 52

Notice: Undefined property: stdClass::$name in /Users/guweigang/github/bullsoft/fmyuedu/backend/app/services/BookService.php on line 53

But there is nothing wrong with mode HYDRATE_RECORDS.

Is this a bug?

@sergeyklay
Copy link
Contributor

unit-tests/ModelsHydrationTest.php:132
unit-tests/ModelsHydrationTest.php:139
unit-tests/ModelsHydrationTest.php:146
unit-tests/ModelsHydrationTest.php:165
unit-tests/ModelsHydrationTest.php:172
unit-tests/ModelsHydrationTest.php:178
unit-tests/ModelsHydrationTest.php:202
unit-tests/ModelsHydrationTest.php:209
unit-tests/ModelsHydrationTest.php:216
unit-tests/ModelsHydrationTest.php:235
unit-tests/ModelsHydrationTest.php:242
unit-tests/ModelsHydrationTest.php:250
unit-tests/ModelsHydrationTest.php:271
unit-tests/ModelsHydrationTest.php:277
unit-tests/ModelsHydrationTest.php:283
unit-tests/ModelsHydrationTest.php:300
unit-tests/ModelsHydrationTest.php:310
unit-tests/ModelsHydrationTest.php:320

@guweigang
Copy link
Contributor Author

@sergeyklay what do you mean?

@sergeyklay
Copy link
Contributor

sergeyklay commented Jul 17, 2016

Files and line where setHydrateMode is used (I mean tests). Have you seen this?

@sergeyklay sergeyklay self-assigned this Aug 4, 2016
@andrew-demb
Copy link
Contributor

Do you use option orm.cast_on_hydrate?
Now phalcon have one bug with Phalcon\Mvc\Model::cloneResultMapHydrate() and this option.

@andrew-demb
Copy link
Contributor

I think you use option orm.cast_on_hydrate, see issue #12191 and pull request #12192.
This PR should solve your problem.

@sergeyklay
Copy link
Contributor

sergeyklay commented Sep 1, 2016

@guweigang

Could you please check 3.0.x branch?

git clone [email protected]:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x

zephir fullclean
zephir build

@sergeyklay sergeyklay added this to the 3.0.2 milestone Sep 1, 2016
@guweigang
Copy link
Contributor Author

Sorry for the late reply,,,, I have set Model behavior in initialize().

self::setUp([
            "notNullValidations" => false,
            "castOnHydrate" => true,
            "forceCasting" => true
]);

The problem is from castOnHydrate, When i comment that line, everything goes right.

@guweigang
Copy link
Contributor Author

guweigang commented Sep 4, 2016

And I just updated to 3.0.x,,, It fixed this issue.

Thx, @sergeyklay @andrew-demb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

5 participants