Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DBClassName so that dev/build can migrate legacy classnames #852

Open
wants to merge 1 commit into
base: 4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class ElementalArea extends DataObject
{
private static $db = [
'OwnerClassName' => 'Varchar(255)',
'OwnerClassName' => 'DBClassName("SilverStripe\\\\ORM\\\\DataObject")',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be DBClassName("SilverStripe\\\\ORM\\\\FieldType\\\\DBVarchar") to keep it effectively a Varchar? Don't understand the change to DataObject.

Copy link
Contributor Author

@tractorcow tractorcow Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the base class that DBClassName should use. The Value of 'OwnerClassName' is a subclass of dataobject.

If you don't add a base name it will assume self::class (which is ElementalArea, and thus wrong).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalkleiner I've just skim read this, but the change from varchar to DBClassName is to make it a proper polymorphic relationship, which means that dev/build in framework can perform modifications on it like it does for other polymorphic relations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should build a proper polymorphic belongs_to in core right @robbieaverill ? :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! I guess it this were replaced with Owner -> DataObject then it'd be even more real

];

private static $has_many = [
Expand Down Expand Up @@ -210,7 +210,7 @@ public function getOwnerPage()
$table = DataObject::getSchema()->tableForField($class, $areaID);
$baseTable = DataObject::getSchema()->baseDataTable($class);
$page = DataObject::get_one($class, [
"\"{$table}\".\"{$areaID}\" = ?" => $this->ID,
"\"{$table}\".\"{$areaID}\" = ?" => $this->ID,
"\"{$baseTable}\".\"ClassName\" = ?" => $class
]);

Expand Down