From 723a8488ac07a2c636fbbdf23f0363ecca582bc7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 6 Mar 2012 15:48:56 +0100 Subject: [PATCH] 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()) --- security/Group.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/security/Group.php b/security/Group.php index 24961f5ed..53f363c3d 100755 --- a/security/Group.php +++ b/security/Group.php @@ -210,27 +210,26 @@ class Group extends DataObject { } /** - * Overloaded getter. - * - * @TODO Where is this used, why is this overloaded? + * 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. * - * @param $limit string SQL - * @param $offset int - * @param $filter string SQL - * @param $sort string SQL - * @param $join string SQL - * @return ComponentSet + * @param String + * @return ManyManyList */ 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) { 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 - $result = $groups->relation('DirectMembers')->where($filter)->sort($sort)->limit($limit); + // First get direct members as a base result + $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); return $result;