Better handling of many_many relationship sorting

This commit is contained in:
UndefinedOffset 2012-05-09 14:39:55 -03:00
parent d075e856bc
commit b10961873c

View File

@ -107,6 +107,7 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
$className=$gridField->getModelClass(); $className=$gridField->getModelClass();
$ownerClass=$gridField->Form->Controller()->class; $ownerClass=$gridField->Form->Controller()->class;
$controllerID=$gridField->Form->Controller()->ID;
$many_many=GridFieldSortableObject::is_sortable_many_many($className); $many_many=GridFieldSortableObject::is_sortable_many_many($className);
if($many_many) { if($many_many) {
@ -131,7 +132,7 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
for($sort=0;$sort<count($data['Items']);$sort++) { for($sort=0;$sort<count($data['Items']);$sort++) {
$id=intval($data['Items'][$sort]); $id=intval($data['Items'][$sort]);
if($many_many) { if($many_many) {
DB::query("UPDATE \"$table\" SET \"SortOrder\" = $sort WHERE \"{$className}ID\" = $id"); DB::query("UPDATE \"$table\" SET \"SortOrder\" = $sort WHERE \"{$className}ID\" = $id AND \"{$ownerClass}ID\" = $controllerID");
}else { }else {
$obj=DataObject::get_by_id($className, $id); $obj=DataObject::get_by_id($className, $id);
$obj->SortOrder=$sort; $obj->SortOrder=$sort;