Jump to:

23367 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Error in the Group Member function?

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

Page: 1
Go to End
Author Topic: 341 Views
  • MonkeyBen
    Avatar
    Community Member
    25 Posts

    Error in the Group Member function? Link to this post

    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;
       }

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Error in the Group Member function? Link to this post

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

  • MonkeyBen
    Avatar
    Community Member
    25 Posts

    Re: Error in the Group Member function? Link to this post

    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.

    341 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.