mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 05:25:13 +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,12 +96,13 @@ 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()
|
||||||
.')');
|
.')');
|
||||||
});
|
});
|
||||||
|
|
||||||
static::created(function (self $post) {
|
static::created(function (self $post) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user