diff --git a/.gitignore b/.gitignore index b512c09d4..b1d62d565 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -node_modules \ No newline at end of file +node_modules +vendor +composer.lock diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index 8c72f6c53..8a0ba4ab5 100644 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -96,12 +96,13 @@ class Post extends AbstractModel /** @var ConnectionInterface $db */ $db = static::getConnectionResolver(); - $post->number = new Expression('('.$db - ->table('posts', 'pn') + $post->number = new Expression('('. + $db->table('posts', 'pn') ->whereRaw($db->getTablePrefix().'pn.discussion_id = '.intval($post->discussion_id)) - ->select($db->raw('max('.$db->getTablePrefix().'pn.number) + 1')) + // IFNULL only works on MySQL/MariaDB + ->selectRaw('IFNULL(MAX('.$db->getTablePrefix().'pn.number), 0) + 1') ->toSql() - .')'); + .')'); }); static::created(function (self $post) {