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.

Data Model Questions

ModelAdmin + searchable_fields + dropdown


10 Posts   3197 Views


1 June 2011 at 9:37pm Community Member, 175 Posts


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.


where should I put this function or edit it?


1 June 2011 at 10:05pm (Last edited: 1 June 2011 10:07pm), Forum Moderator, 1796 Posts

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'...