Created
January 22, 2010 00:19
-
-
Save sminnee/283357 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: sapphire/core/model/Aggregate.php | |
| =================================================================== | |
| --- sapphire/core/model/Aggregate.php (revision 97402) | |
| +++ sapphire/core/model/Aggregate.php (working copy) | |
| @@ -85,12 +85,18 @@ | |
| $attribute = $args ? $args[0] : 'ID'; | |
| $table = null; | |
| - | |
| - foreach (ClassInfo::ancestry($this->type, true) as $class) { | |
| + | |
| + $ancestry = ClassInfo::ancestry($this->type, true); | |
| + foreach ($ancestry as $class) { | |
| $fields = DataObject::custom_database_fields($class); | |
| if (array_key_exists($attribute, $fields)) { $table = $class; break; } | |
| } | |
| + // Special case for these built-in fields | |
| + if(!$table && in_array($attribute, array('LastEdited', 'Created', 'ClassName'))) { | |
| + $table = array_pop($ancestry); | |
| + } | |
| + | |
| if (!$table) user_error("Couldn't find table for field $attribute in type {$this->type}", E_USER_ERROR); | |
| $query = $this->query("$func(\"$table\".\"$attribute\")"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment