Skip to content

Commit

Permalink
Merge pull request unclecheese#54 from JonasAleknavicius/master
Browse files Browse the repository at this point in the history
DataObjectManager, SortableDataObject, onBeforeWrite performance
  • Loading branch information
unclecheese committed Jun 4, 2012
2 parents b75a9a6 + aab754f commit 5804ab9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions code/SortableDataObject.php
Expand Up @@ -118,8 +118,9 @@ public function augmentSQL(SQLQuery &$query)
public function onBeforeWrite()
{
if(!$this->owner->ID) {
if($peers = DataObject::get($this->owner->class))
$this->owner->SortOrder = $peers->Count()+1;
$sql = new SQLQuery("count(ID)", array_shift(ClassInfo::dataClassesFor($this->owner->class)));
$val = $sql->execute()->value();
$this->owner->SortOrder = is_numeric($val)?$val+1:1;
}
}

Expand Down

0 comments on commit 5804ab9

Please sign in to comment.