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.4] Model::findFirst() w/ for_update leads to a PDOException #10623

Closed
ocrdeveloper opened this issue Jul 9, 2015 · 2 comments
Closed

[2.0.4] Model::findFirst() w/ for_update leads to a PDOException #10623

ocrdeveloper opened this issue Jul 9, 2015 · 2 comments

Comments

@ocrdeveloper
Copy link

The following code worked correctly through Phalcon 2.0.3

/**
 * DailySearchStats Model
 */
class DailySearchStats extends \Phalcon\Mvc\Model 
{

   ...

    /**
     * @return DailySearchStats
     */
    public static function findFirst($parameters = [])
    {
        return parent::findFirst($parameters);
    }

    ...

    public static function increment()
    {
        $date = date('Y-m-d');

        $stat = DailySearchStats::findFirst([
            'conditions' => 'curdate = :theDate:',
            'bind'=>[
                'theDate' => $date
            ],
            'for_update' => true
        ]);

        if (!$stat) {
            $stat = new DailySearchStats();
            $stat->setCurdate($date);
            $stat->count = 1;
        } else {
            $stat->count++;
        }
        $stat->save();
    }
}

Then in the controller:

...
public function searchAction(){
    DailySearchStats::increment();
}

However, as of 2.0.4, I get the following error

PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

The line with the error is actually return parent::findFirst($parameters);.

If I remove "for_update" => true, the error disappears and everything works just fine.

I know there are plenty of other ways to perform the operation above but I'm just reporting the new bug from introduced upgrading from 2.0.3 to 2.0.4.

@andresgutierrez
Copy link
Contributor

Duplicate of #10621 and it's already fixed in the 2.0.x branch

@ocrdeveloper
Copy link
Author

Thanks for the update. I did a search before posting but looks like I barely missed it.

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

No branches or pull requests

2 participants