Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created January 22, 2010 00:19
Show Gist options
  • Select an option

  • Save sminnee/283357 to your computer and use it in GitHub Desktop.

Select an option

Save sminnee/283357 to your computer and use it in GitHub Desktop.
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