Skip to content

Instantly share code, notes, and snippets.

@dhensby
Last active December 10, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhensby/4511316 to your computer and use it in GitHub Desktop.
Save dhensby/4511316 to your computer and use it in GitHub Desktop.
Create a DataObjectSet from an SS_Query - SilverStripe 2.x
<?php
//2.x
function queryToDos(SS_Query $qry) {
$dos = new DataObjectSet();
while ($record = $qry->next()) {
$dos->push(new {$record['ClassName']}($record));
}
return $dos;
}
//3.x
function queryToArrayList(SS_Query $qry) {
$list = ArrayList::create();
while ($record = $qry->next()) {
$list->push(Injector::inst()->create($record['ClassName'], $record));
}
return $list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment