Skip to content

[BUG] \Phalcon\Mvc\Model\Query\Builder ... #1542

Description

@ovr

Hi All)

/**
 * @var $model \User\Model\Follow\User
 */
$model = $this->getModel();

$builder = $this->createQuery('fu')
    ->columns('fu.*, Follower.*')

    ->join('User\Model\User', 'fu.user_id = Follower.id', 'Follower')

    ->where('fu.author_user_id = '.$userId)
    ->andWhere('fu.user_id <> '.$userId)

    ->orderBy('fu.'.$model->getPrimaryKey().' DESC');

if ($days >= 1) {
    $builder->andWhere('DATE(fu.createdDate) >= SUBDATE(CURRENT_DATE, '.$days.')');
} else {
    $builder->andWhere('DATE(fu.createdDate) >= CURRENT_DATE');
}

Exception:

Fatal error: Uncaught exception 'Phalcon\Mvc\Model\Exception' with message 'Column 'CURRENT_DATE' doesn't belong to any of the selected models (1), when preparing: SELECT fu., Follower. FROM [User\Model\Follow\User] AS [fu] JOIN [User\Model\User] AS [Follower] ON fu.user_id = Follower.id WHERE ((fu.author_user_id = 11000) AND (fu.user_id <> 11000)) AND (DATE(fu.createdDate) >= SUBDATE(CURRENT_DATE, 1)) ORDER BY fu.favoriteauthor_id DESC LIMIT 100' in /home/zaets28rus/www/uniqhand-sandbox/app/modules/user/models/Follow/UserTable.php on line 184

Phalcon\Mvc\Model\Exception: Column 'CURRENT_DATE' doesn't belong to any of the selected models (1), when preparing: SELECT fu., Follower. FROM [User\Model\Follow\User] AS [fu] JOIN [User\Model\User] AS [Follower] ON fu.user_id = Follower.id WHERE ((fu.author_user_id = 11000) AND (fu.user_id <> 11000)) AND (DATE(fu.createdDate) >= SUBDATE(CURRENT_DATE, 1)) ORDER BY fu.favoriteauthor_id DESC LIMIT 100 in /home/zaets28rus/www/uniqhand-sandbox/app/modules/user/models/Follow/UserTable.php on line 184

When i am using CURDATE() its okey

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    not a bugReported issue is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions