mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 06:59:42 +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
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
node_modules
|
||||
vendor
|
||||
composer.lock
|
||||
|
|
|
@ -96,10 +96,11 @@ 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()
|
||||
.')');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user