Skip to content

Commit

Permalink
BUG Return an empty list when trying to get versions for DataObject n…
Browse files Browse the repository at this point in the history
…ot yet in the DB
  • Loading branch information
Maxime Rainville committed Feb 15, 2022
1 parent 81a3064 commit 28cbfaa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\Connect\NullDatabase;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -2100,11 +2101,18 @@ public function VersionsList()
*/
public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "")
{
/** @var DataObject $owner */
$owner = $this->owner;

// When an object is not yet in the Database, we can't get its versions
if (!$owner->isInDB()) {
return ArrayList::create();
}

// Make sure the table names are not postfixed (e.g. _Live)
$oldMode = static::get_reading_mode();
static::set_stage(static::DRAFT);

$owner = $this->owner;
$list = DataObject::get(DataObject::getSchema()->baseDataClass($owner), $filter, $sort, $join, $limit);
if ($having) {
// @todo - This method doesn't exist on DataList
Expand Down

0 comments on commit 28cbfaa

Please sign in to comment.