3060 Posts in 864 Topics by 646 members
| Go to End | Next > | |
| Author | Topic: | 2187 Views |
-
ModelAdmin + searchable_fields + dropdown

14 March 2011 at 5:13am Last edited: 19 May 2011 10:02am
hi,
class Program extends DataObject {
...
static $has_one = array(
'Acount' => 'Account'
);static $belongs_many_many = array(
'Categories' => 'CategoryPage',
);static $searchable_fields = array (
'program_id' => array(
'title' => 'Program ID',
'field' => 'NumericField',
'filter' => 'PartialMatchFilter'
),
'name' => array('title'=>'Programmname'),
'URLSegment' => array('title'=>'URL Segment'),
'description' => array('title'=>'Beschreibung'),'Categories.ID' => array('title' => 'Kategorie'),
'Account.ID' => array('title'=>'Account')
);I have some problems with the 2 last entries in searchable_fields. For the categories I get dropdownfield with all Categories, but if I perform a search it results in an sql error. It only works if I use "Categories.Name", but then I get a textfield instead a dropdown.
Error: "Couldn't run query: SELECT DISTINCT count(*) FROM "Program" INNER JOIN "CategoryPage_Programs" AS "CategoryPage_Programs"
ON "CategoryPage_Programs"."ProgramID" = "Program"."ID" LEFT JOIN "SiteTree" AS "SiteTree"
ON "CategoryPage_Programs"."CategoryPageID" = "SiteTree"."ID" WHERE ("CategoryPage"."ID" IN ('21'))
Unknown column 'CategoryPage.ID' in 'where clause'" at line 525 of /var/www/xxx/sapphire/core/model/MySQLDatabase.phpAnd the "Account.ID" also returns a dropdown as expectet, but the dropdown shows me only the IDs instead of the Account Names.
Whats wrong here?
thx
-
Re: ModelAdmin + searchable_fields + dropdown

5 May 2011 at 3:03am
instead of 'Categories.ID' => array('title' => 'Kategorie') you have to use 'CategoriesID' => array('title' => 'Kategorie')
I think -
Re: ModelAdmin + searchable_fields + dropdown

6 May 2011 at 12:44am
no sorry, this results in
[User Error] Uncaught Exception: Unable to traverse to related object field [CategoriesID] on [Program]
-
Re: ModelAdmin + searchable_fields + dropdown

6 May 2011 at 2:39am
Oh, sorry, I was should have read your post more carefully, i thought you have a has_many relation, in fact it seems that it is a many_many.
nvm what I said then.I never did filtering on a many_many but actually I will run into that problem tomorrow or maybe on Monday, I will post again after I had my try on it.
-
Re: ModelAdmin + searchable_fields + dropdown

6 May 2011 at 2:58am
hi zauberfisch,
thank you, waiting for your results on that
-
Re: ModelAdmin + searchable_fields + dropdown

27 May 2011 at 10:58am
Any luck on this issue, I'm having the same problem. Both with a has_one and a has_many relationship.
-
Re: ModelAdmin + searchable_fields + dropdown

27 May 2011 at 7:19pm
hello, sorry that it is taking me that long, i still have the problem, and i still want to find a way, but it needs to wait for I have a couple of other things with higher priority.
filtering on a has_one is really simple, here an example class:
class Hotel extends DataObject {
static $db = array(
'Title' => 'Text'
);
static $has_one = array(
'State' => 'State'
);
static $searchable_fields = array(
'Title' => array('title' => 'Name'),
'StateID' => array(
'title'=>'State Name'
)
);
} -
Re: ModelAdmin + searchable_fields + dropdown

27 May 2011 at 9:04pm Last edited: 27 May 2011 9:08pm
I have hacked up getSearchQuery($searchCriteria) in my ModelAdmin_CollectionController to handle custom search requirements. I sometimes need to add/modify the fields in the DataObject's scaffoldSearchFields() as well. It's not perfect, but it's not that bad and gets the job done easily.
e.g.
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;
}
| 2187 Views | ||
| Go to Top | Next > |




