Hi All I have a class called shared data that extends ModelAdmin:
class SharedData extends ModelAdmin
{
// Managed models - Each model automatically get a tab added to Shared Data admin page
public static $managed_models = array(
'EmpArea' => array('title' => 'Employment Areas'),
);
public static $model_importers = array(
'EmpArea' => 'CsvBulkLoader',
);
public static $url_segment = 'shared-data';
public static $menu_title = 'Shared Data';
// Place it right below the Pages menu item which has a priority of 10
public static $menu_priority = 9;
}
and a model called EmpArea:
class EmpArea extends MultilingualDataObject {
public static $db = array(
'Name' => 'Varchar'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldtoTab('Root.Main', new TextField('Name', 'Employment Area'));
// add extension updateCMSFields to include translations
$this->doExtend("updateCMSFields",$fields, get_class());
return $fields;
}
}
everything displays perfectly and the grid can be sorted with the sort ascending/descending grid headers and you can navigate to the individual models to vie/edit them. The problem arises when you filter the model with the filter widget on the left menu, any filter constraint added will return the correctly filtered items but the items can no longer be selected to view/edit them. When you attempt to navigate to a filtered model you get a vagrant error:
ERROR [User Error]: Couldn't run query:
SELECT DISTINCT "MultilingualDataObject"."ID"
FROM "MultilingualDataObject"
WHERE ("EmpArea"."Name" LIKE '%HR%') AND ("MultilingualDataObject"."ClassName" IN ('EmpArea'))
LIMIT 30
Unknown column 'EmpArea.Name' in 'where clause'
IN GET /admin/shared-data/EmpArea/EditForm/field/EmpArea/item/420/edit?q%5BName%5D=HR&action_search=Apply+Filter
Line 580 in /vagrant/framework/model/MySQLDatabase.php
Source
======
571: }
572:
573: public function databaseError($msg, $errorLevel = E_USER_ERROR) {
574: // try to extract and format query
575: if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
576: $formatter = new SQLFormatter();
577: $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
578: }
579:
* 580: user_error($msg, $errorLevel);
581: }
582:
583: /**
584: * Return a boolean type-formatted string
585: *
586: * @param array $values Contains a tokenised list of info about this data type
The URL for one of the is:
/admin/shared-data/EmpArea/EditForm/field/EmpArea/item/420/edit
After a filter is applied it changes to:
/admin/shared-data/EmpArea/EditForm/field/EmpArea/item/420/edit?q%5BName%5D=HR&action_search=Apply+Filter
If you delete the filter part out of the url the page navigates fine.
Any help or suggestions would be greatly appreciated.
Matt