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.

Data Model Questions /

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

ModelAdmin + searchable_fields + dropdown


Go to End


10 Posts   7501 Views

Avatar
danzzz

Community Member, 175 Posts

1 June 2011 at 9:37pm

hi

the dropdown with the has_one relations now works ... but why I had no titles in my dropdown?
because the related DO had no "Title" field in database. I added this field to the "Account" DO and now this works.

for the many_many I'm still searching a solution.

@swaiba:

where should I put this function or edit it?

Avatar
swaiba

Forum Moderator, 1899 Posts

1 June 2011 at 10:05pm

Edited: 01/06/2011 10:07pm

getSearchQuery($searchCriteria) in my ModelAdmin_CollectionController

class MyAdmin extends ModelAdmin {
	...
	static $collection_controller_class = "MyAdmin_CollectionController";
	...
}

class MyAdmin_CollectionController extends ModelAdmin_CollectionController {
	...
	function getSearchQuery($searchCriteria) { 
	   $query = parent::getSearchQuery($searchCriteria); 
	   if ($this->modelClass == 'MyDataObject'){ 
	      $query->where[] = 'EXISTS (SELECT 1 FROM SomeTable st' 
	            .' WHERE MyDataObject.ID = st.MyDataObjectID' 
	            .' AND st.Field='.$searchCriteria['MyFieldFromSearchFormFields'].')'; 
	   } 
	   return $query; 
	}
	...
}

and I do you this to provide searching for complex relations where is has_one that has_one that has a man_many with 'xyz'...

Go to Top