Skip to content
This repository
Browse code

If a DataObject has a many_many to a SiteTree subclass, and that subc…

…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...
commit 119739de682e4653bc2836939111955b60cfb51f 1 parent f794e98
unclecheese authored June 04, 2012

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  search/filters/SearchFilter.php
2  search/filters/SearchFilter.php
@@ -142,7 +142,7 @@ function getDbName() {
142 142
 		// Todo: move to somewhere more appropriate, such as DataMapper, the magical class-to-be?
143 143
 		$candidateClass = $this->model;
144 144
 		while($candidateClass != 'DataObject') {
145  
-			if(singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) break;
  145
+			if(DataObject::has_own_table($candidateClass) && singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) break;
146 146
 			$candidateClass = get_parent_class($candidateClass);
147 147
 		}
148 148
 		if($candidateClass == 'DataObject') user_error("Couldn't find field $this->name in any of $this->model's tables.", E_USER_ERROR);

0 notes on commit 119739d

Please sign in to comment.
Something went wrong with that request. Please try again.