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; $this->dataList = $sourceClass;
} else { } else {
$this->dataList = DataObject::get($sourceClass)->where($sourceFilter) $this->dataList = DataObject::get($sourceClass)->where($sourceFilter)->sort($sourceSort);
->sort($sourceSort)->join($sourceJoin); if($sourceJoin) $this->dataList = $this->dataList->join($sourceJoin);
// Grab it from the form relation, if available. // Grab it from the form relation, if available.
$this->getDataListFromForm = true; $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. * Add an join clause to this data list's query.
*/ */
public function join($join) { public function join($join) {
Deprecation::notice('3.0', 'Use innerJoin() or leftJoin() instead.');
$this->dataQuery->join($join); $this->dataQuery->join($join);
return $this; return $this;
} }

View File

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

View File

@ -208,10 +208,16 @@ class Group extends DataObject {
public function Members($filter = "", $sort = "", $join = "", $limit = "") { public function Members($filter = "", $sort = "", $join = "", $limit = "") {
// Get a DataList of the relevant groups // Get a DataList of the relevant groups
$groups = DataList::create("Group")->byIDs($this->collateFamilyIDs()); $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 // Call the relation method on the DataList to get the members from all the groups
return $groups->relation('DirectMembers') $result = $groups->relation('DirectMembers')->where($filter)->sort($sort)->limit($limit);
->where($filter)->sort($sort)->join($join)->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(); if(!count($groupIDs)) return new ArrayList();
$members = DataObject::get( $members = DataObject::get('Member')->where("\"Group\".\"ID\" IN (" . implode(",",$groupIDs) . ")")
Object::getCustomClass('Member'), ->leftJoin("Group_Members", "\"Member\".\"ID\" = \"Group_Members\".\"MemberID\"")
$_filter = "\"Group\".\"ID\" IN (" . implode(",",$groupIDs) . ")", ->leftJoin("Group", "\"Group_Members\".\"GroupID\" = \"Group\".\"ID\"");
$_sort = "",
$_join = "LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\" " .
"LEFT JOIN \"Group\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\" "
);
return $members; return $members;
} }
@ -414,13 +410,11 @@ class Permission extends DataObject {
$SQL_codes = join("','", $SQLa_codes); $SQL_codes = join("','", $SQLa_codes);
// Via Roles are groups that have the permission via a role // Via Roles are groups that have the permission via a role
return DataObject::get('Group', return DataObject::get('Group')->where("\"PermissionRoleCode\".\"Code\" IN ('$SQL_codes') OR \"Permission\".\"Code\" IN ('$SQL_codes')")
"\"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\"")
"LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\" ->leftJoin('PermissionRole', "\"Group_Roles\".\"PermissionRoleID\" = \"PermissionRole\".\"ID\"")
LEFT JOIN \"Group_Roles\" ON \"Group_Roles\".\"GroupID\" = \"Group\".\"ID\" ->leftJoin('PermissionRoleCode', "\"PermissionRoleCode\".\"RoleID\" = \"PermissionRole\".\"ID\"");
LEFT JOIN \"PermissionRole\" ON \"Group_Roles\".\"PermissionRoleID\" = \"PermissionRole\".\"ID\"
LEFT JOIN \"PermissionRoleCode\" ON \"PermissionRoleCode\".\"RoleID\" = \"PermissionRole\".\"ID\"");
} }

View File

@ -2,12 +2,16 @@
class DataQueryTest extends SapphireTest { 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 = 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()); $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());
} }
} }