MINOR: Removed use of deprecated join() in favour of innerJoin() and leftJoin().

This commit is contained in:
Sam Minnee 2011-10-29 17:11:27 +13:00
parent b0b5fea3f5
commit 0d683dd8ef
6 changed files with 30 additions and 23 deletions

View File

@ -240,8 +240,8 @@ class TableListField extends FormField {
$this->dataList = $sourceClass;
} else {
$this->dataList = DataObject::get($sourceClass)->where($sourceFilter)
->sort($sourceSort)->join($sourceJoin);
$this->dataList = DataObject::get($sourceClass)->where($sourceFilter)->sort($sourceSort);
if($sourceJoin) $this->dataList = $this->dataList->join($sourceJoin);
// Grab it from the form relation, if available.
$this->getDataListFromForm = true;
}

View File

@ -97,6 +97,7 @@ class DataList extends ViewableData implements SS_List {
* Add an join clause to this data list's query.
*/
public function join($join) {
Deprecation::notice('3.0', 'Use innerJoin() or leftJoin() instead.');
$this->dataQuery->join($join);
return $this;
}

View File

@ -1336,7 +1336,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
if($this->model) $result->setModel($this->model);
if($this->ID) $result->setForeignID($this->ID);
$result = $result->where($filter)->limit($limit)->sort($sort)->join($join);
$result = $result->where($filter)->limit($limit)->sort($sort);
if($join) $result = $result->join($join);
return $result;
}
@ -2496,7 +2497,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
// Todo: Determine if we can deprecate for 3.0.0 and use DI or something instead
// Todo: Make the $containerClass method redundant
if($containerClass != "DataList") user_error("The DataObject::get() \$containerClass argument has been deprecated", E_USER_NOTICE);
$result = DataList::create($callerClass)->where($filter)->sort($sort)->join($join)->limit($limit);
$result = DataList::create($callerClass)->where($filter)->sort($sort)->limit($limit);
if($join) $result = $result->join($join);
$result->setModel(DataModel::inst());
return $result;
}

View File

@ -209,9 +209,15 @@ class Group extends DataObject {
// Get a DataList of the relevant groups
$groups = DataList::create("Group")->byIDs($this->collateFamilyIDs());
if($sort || $join || $limit) {
Deprecation::notice('3.0', "The sort, join, and limit arguments are deprcated, use sort(), join() and limit() on the resulting DataList instead.");
}
// Call the relation method on the DataList to get the members from all the groups
return $groups->relation('DirectMembers')
->where($filter)->sort($sort)->join($join)->limit($limit);
$result = $groups->relation('DirectMembers')->where($filter)->sort($sort)->limit($limit);
if($join) $result = $result->join($join);
return $result;
}
/**

View File

@ -391,13 +391,9 @@ class Permission extends DataObject {
if(!count($groupIDs)) return new ArrayList();
$members = DataObject::get(
Object::getCustomClass('Member'),
$_filter = "\"Group\".\"ID\" IN (" . implode(",",$groupIDs) . ")",
$_sort = "",
$_join = "LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\" " .
"LEFT JOIN \"Group\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\" "
);
$members = DataObject::get('Member')->where("\"Group\".\"ID\" IN (" . implode(",",$groupIDs) . ")")
->leftJoin("Group_Members", "\"Member\".\"ID\" = \"Group_Members\".\"MemberID\"")
->leftJoin("Group", "\"Group_Members\".\"GroupID\" = \"Group\".\"ID\"");
return $members;
}
@ -414,13 +410,11 @@ class Permission extends DataObject {
$SQL_codes = join("','", $SQLa_codes);
// Via Roles are groups that have the permission via a role
return DataObject::get('Group',
"\"PermissionRoleCode\".\"Code\" IN ('$SQL_codes') OR \"Permission\".\"Code\" IN ('$SQL_codes')",
"",
"LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\"
LEFT JOIN \"Group_Roles\" ON \"Group_Roles\".\"GroupID\" = \"Group\".\"ID\"
LEFT JOIN \"PermissionRole\" ON \"Group_Roles\".\"PermissionRoleID\" = \"PermissionRole\".\"ID\"
LEFT JOIN \"PermissionRoleCode\" ON \"PermissionRoleCode\".\"RoleID\" = \"PermissionRole\".\"ID\"");
return DataObject::get('Group')->where("\"PermissionRoleCode\".\"Code\" IN ('$SQL_codes') OR \"Permission\".\"Code\" IN ('$SQL_codes')")
->leftJoin('Permission', "\"Permission\".\"GroupID\" = \"Group\".\"ID\"")
->leftJoin('Group_Roles', "\"Group_Roles\".\"GroupID\" = \"Group\".\"ID\"")
->leftJoin('PermissionRole', "\"Group_Roles\".\"PermissionRoleID\" = \"PermissionRole\".\"ID\"")
->leftJoin('PermissionRoleCode', "\"PermissionRoleCode\".\"RoleID\" = \"PermissionRole\".\"ID\"");
}

View File

@ -2,12 +2,16 @@
class DataQueryTest extends SapphireTest {
/**
* Test the join() method of the DataQuery object
* Test the leftJoin() and innerJoin method of the DataQuery object
*/
function testJoin() {
function testJoins() {
$dq = new DataQuery('Member');
$dq->join("INNER JOIN \"Group_Members\" ON \"Group_Members\".\"MemberID\" = \"Member\".\"ID\"");
$dq->innerJoin("Group_Members", "\"Group_Members\".\"MemberID\" = \"Member\".\"ID\"");
$this->assertContains("INNER JOIN \"Group_Members\" ON \"Group_Members\".\"MemberID\" = \"Member\".\"ID\"", $dq->sql());
$dq = new DataQuery('Member');
$dq->leftJoin("Group_Members", "\"Group_Members\".\"MemberID\" = \"Member\".\"ID\"");
$this->assertContains("LEFT JOIN \"Group_Members\" ON \"Group_Members\".\"MemberID\" = \"Member\".\"ID\"", $dq->sql());
}
}