Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Error in the Group Member function?


Reply

3 Posts   374 Views

Avatar
MonkeyBen

29 June 2012 at 2:24am Community Member, 25 Posts

Hi all,

I have been trying to use the JOIN arguement in the Group->Member() function on a website that has SS version 2.4.5 on it. I think there is a bug in the function.

Shouldn't: -

$join .= " INNER JOIN \"$table\" ON \"$table\".\"MemberID\" = \"Member\".\"ID\"" . Convert::raw2sql($join);


Be: -

$join = " INNER JOIN \"$table\" ON \"$table\".\"MemberID\" = \"Member\".\"ID\"" . Convert::raw2sql($join);

i.e. the first one is adding the JOIN twice is it not? I am getting an error until I patch that line and it works fine.

public function Members($limit = "", $offset = "", $filter = "", $sort = "", $join = "") {
      $table = "Group_Members";
      if($filter) $filter = is_array($filter) ? $filter : array($filter);
      
      if( is_numeric( $limit ) ) {
         if( is_numeric( $offset ) )
            $limit = "$limit OFFSET $offset";
         else
            $limit = "$limit OFFSET 0";
      } else {
         $limit = "";
      }
      
      // Get all of groups that this group contains
      $groupFamily = implode(", ", $this->collateFamilyIDs());
      
      $filter[] = "\"$table\".\"GroupID\" IN ($groupFamily)";
      $join .= " INNER JOIN \"$table\" ON \"$table\".\"MemberID\" = \"Member\".\"ID\"" . Convert::raw2sql($join);
      
      $result = singleton("Member")->instance_get(
         $filter,
         $sort,
         $join,
         $limit,
         "ComponentSet" // datatype
         );
         
      if(!$result) $result = new ComponentSet();

      $result->setComponentInfo("many-to-many", $this, "Group", $table, "Member");
      foreach($result as $item) $item->GroupID = $this->ID;
      return $result;
   }

Avatar
Willr

30 June 2012 at 12:46pm Forum Moderator, 5511 Posts

With that change isn't it ignore the $join argument completely?

Avatar
MonkeyBen

30 June 2012 at 10:58pm Community Member, 25 Posts

It doesn't ignore the $join arguement because the $join string is being over written with the Group_Members join string, and then at the end the $join arguement it being added (being run through the convert::raw2sql() function. With .= the raw $join arguement is also being added to the front of the string as well as the converted version at the end.