mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 07:41:04 +08:00
fix: first posts having NULL
as value for number column (#3414)
* fix: first posts having `NULL` as value for `number` column * chore: add note about raw db function `IFNULL`
This commit is contained in:
parent
2e89ba3c94
commit
1954d0383e
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
node_modules
|
||||
node_modules
|
||||
vendor
|
||||
composer.lock
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user