BUGFIX Fixed Group->Members() overloaded relation getter to avoid filtering on zero-value foreign keys, producing empty rather than inherited results (important for the GridField used in Group->getCMSFields())

This commit is contained in:
Ingo Schommer 2012-03-06 15:48:56 +01:00
parent bd1f652fe9
commit 723a8488ac

View File

@ -210,27 +210,26 @@ class Group extends DataObject {
} }
/** /**
* Overloaded getter. * Get many-many relation to {@link Member},
* including all members which are "inherited" from children groups of this record.
* See {@link DirectMembers()} for retrieving members without any inheritance.
* *
* @TODO Where is this used, why is this overloaded? * @param String
* * @return ManyManyList
* @param $limit string SQL
* @param $offset int
* @param $filter string SQL
* @param $sort string SQL
* @param $join string SQL
* @return ComponentSet
*/ */
public function Members($filter = "", $sort = "", $join = "", $limit = "") { public function Members($filter = "", $sort = "", $join = "", $limit = "") {
// Get a DataList of the relevant groups
$groups = DataList::create("Group")->byIDs($this->collateFamilyIDs());
if($sort || $join || $limit) { 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."); 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 // First get direct members as a base result
$result = $groups->relation('DirectMembers')->where($filter)->sort($sort)->limit($limit); $result = $this->DirectMembers();
// Remove the default foreign key filter in prep for re-applying a filter containing all children groups.
// Filters are conjunctive in DataQuery by default, so this filter would otherwise overrule any less specific ones.
$result->dataQuery()->removeFilterOn('Group_Members');
// Now set all children groups as a new foreign key
$groups = DataList::create("Group")->byIDs($this->collateFamilyIDs());
$result = $result->forForeignID($groups->column('ID'))->where($filter)->sort($sort)->limit($limit);
if($join) $result = $result->join($join); if($join) $result = $result->join($join);
return $result; return $result;