Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ModelAdmin Filter results not working


Go to End


736 Views

Avatar
MattMan9

Community Member, 3 Posts

12 January 2015 at 11:09am

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