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.10] Bug - ODM - findByld #12010

Closed
Mont4 opened this issue Jul 24, 2016 · 6 comments
Closed

[2.0.10] Bug - ODM - findByld #12010

Mont4 opened this issue Jul 24, 2016 · 6 comments
Assignees
Labels
enhancement Enhancement to the framework
Milestone

Comments

@Mont4
Copy link

Mont4 commented Jul 24, 2016

Hi,
In ODM models, if id doesn't found in Database when using findByld function, the false value should be returned.

$id = 'not exist id';
$user = Users::findById($id);

if($user == false){
      // redirect
}
@Mont4 Mont4 changed the title Phalcon 2.0.10 - Bug - ODM - findByld [2.0.10] Bug - ODM - findByld Jul 24, 2016
@sergeyklay
Copy link
Contributor

What about:

if (!$user->count()) {
    // redirect
}

@Mont4
Copy link
Author

Mont4 commented Jul 24, 2016

when call findById($id) that id doesn't exist
this error happen.

Invalid object ID
#0 [internal function]: MongoId->__construct('s')
#1 [internal function]: Phalcon\Mvc\Collection::findById('s')
#2 /Users/iMohammad/Development/Phalcon/apps/backend/controllers/AdminAbstract.php(128): call_user_func(Array, 's')
#3 [internal function]: App\Backend\Controllers\AdminAbstract->confirmAction('s')
#4 [internal function]: Phalcon\Dispatcher->dispatch()
#5 /Users/iMohammad/Development/Phalcon/public/index.php(44): Phalcon\Mvc\Application->handle()
#6 {main}

@sergeyklay
Copy link
Contributor

sergeyklay commented Jul 24, 2016

Hmm.. Okay. What about:

$user = Users::findById(new \MongoId('545eb081631d16153a293a66'));

In any case, what do you suggest? To add regexp to the findById like this?

/^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)/i

or

/^[a-f\d]{24}$/i

@Mont4
Copy link
Author

Mont4 commented Jul 24, 2016

Whenever this error occurs, it means id characters count are not 24.
I did not pay attention to that

@Mont4
Copy link
Author

Mont4 commented Jul 24, 2016

yes, it's good
tnx

@sergeyklay sergeyklay added the enhancement Enhancement to the framework label Jul 24, 2016
@sergeyklay sergeyklay self-assigned this Jul 24, 2016
@sergeyklay sergeyklay added this to the 3.0.0 milestone Jul 24, 2016
@sergeyklay
Copy link
Contributor

Fixed in the 2.1.x branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to the framework
Projects
None yet
Development

No branches or pull requests

2 participants