Skip to content

Commit

Permalink
If a DataObject has a many_many to a SiteTree subclass, and that subc…
Browse files Browse the repository at this point in the history
…lass has no database fields defined, and $this->name is "ID", this function will errantly return "SiteTreeSubClass.ID", which can never exist in a search query, since there is no such table as SiteTreeSubClass. The problem is that DataObject::hasOwnTableDatabaseField() is a little eager when passed an argument of "ID." It doesn't check to see if the object has its own table first.
  • Loading branch information
unclecheese committed Jun 4, 2012
1 parent f794e98 commit 119739d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion search/filters/SearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getDbName() {
// Todo: move to somewhere more appropriate, such as DataMapper, the magical class-to-be?
$candidateClass = $this->model;
while($candidateClass != 'DataObject') {
if(singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) break;
if(DataObject::has_own_table($candidateClass) && singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) break;
$candidateClass = get_parent_class($candidateClass);
}
if($candidateClass == 'DataObject') user_error("Couldn't find field $this->name in any of $this->model's tables.", E_USER_ERROR);
Expand Down

0 comments on commit 119739d

Please sign in to comment.