UndefinedOffset / SortableGridField

Adds drag and drop functionality to Silverstripe's GridField
BSD 3-Clause "New" or "Revised" License
93 stars 62 forks source link

mapTableNameAndReturn can't parse namespace+classname into mysql tablename #113

Closed wubies closed 6 years ago

wubies commented 6 years ago

Using CMS/Framework 4.00 and SortableGridField 2.0.1

I have set my pages within a namespace...

namespace NorthChurch;

So when I try to add sortablegridfield...

$config->addComponent(new GridFieldSortableRows('SortOrder'),'GridFieldManyRelationHandler');

I get a mysql error because it can't translate namespace.classname into namespace_classname for the mysql query.

[Emergency] Uncaught SilverStripe\ORM\Connect\DatabaseException: Couldn't run query: UPDATE "NorthChurch\HomePageCarousel" SET "SortOrder" = 1 WHERE "ID" = 2 42S02-1146: Table 'northchurch.NorthChurch\HomePageCarousel' doesn't exist

I was able to quickfix by adding the following to mapTableNameAndReturn function (line 767 as I couldn't find the right way to convert namespace/classname).

$realName = str_replace("\\","_",$realName);

There may be a better way, but this works for now. There are no issues if the DBObject has a $table_name set, but I'm not sure if this is enforced, so may need to work without it.

robbieaverill commented 6 years ago

Yeah the way this should be done is to use the DataObjectSchema: $tableName = DataObject::getSchema()->tableName($realName)

UndefinedOffset commented 6 years ago

Yep easy fix, I'm away this week so I'll put the fix in place next week.

UndefinedOffset commented 6 years ago

This is now fixed and tagged 2.0.2