mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 09:48:15 +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
|
node_modules
|
||||||
|
vendor
|
||||||
|
composer.lock
|
||||||
|
|
|
@ -96,10 +96,11 @@ class Post extends AbstractModel
|
||||||
|
|
||||||
/** @var ConnectionInterface $db */
|
/** @var ConnectionInterface $db */
|
||||||
$db = static::getConnectionResolver();
|
$db = static::getConnectionResolver();
|
||||||
$post->number = new Expression('('.$db
|
$post->number = new Expression('('.
|
||||||
->table('posts', 'pn')
|
$db->table('posts', 'pn')
|
||||||
->whereRaw($db->getTablePrefix().'pn.discussion_id = '.intval($post->discussion_id))
|
->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()
|
->toSql()
|
||||||
.')');
|
.')');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user