Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ModelAdmin + searchable_fields + dropdown

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

Page: 1 2
Go to End
Author Topic: 3156 Views
  • danzzz
    Community Member
    175 Posts

    Re: ModelAdmin + searchable_fields + dropdown Link to this post


    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?

  • swaiba
    Forum Moderator
    1792 Posts

    Re: ModelAdmin + searchable_fields + dropdown Link to this post

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

Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.