Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ORM] DataList::relation doesn't work for Group.Memberss #8043

Open
JorisDebonnet opened this issue Apr 30, 2018 · 3 comments
Open

[ORM] DataList::relation doesn't work for Group.Memberss #8043

JorisDebonnet opened this issue Apr 30, 2018 · 3 comments

Comments

@JorisDebonnet
Copy link
Contributor

Affected Version

silverstripe/recipe-cms 1.1.0
(i.e. framework 4.1.0)

Description

DataList::relation has the following example in the documentation:

// Get members from all Groups:
DataList::Create(\SilverStripe\Security\Group::class)->relation("Members");

But this returns an empty list. From the example's description, that should at least list the Default Administrator (who belongs to the Administrator Group). Is the method broken, or is the example bad?

(I'm trying to fix an issue in symbiote/silverstripe-memberprofiles where I have the same issue of relation("Members") returning an empty list)

Steps to Reproduce

Just try this:

// Get number of Members that are linked to any Group (supposedly):
echo DataList::Create(\SilverStripe\Security\Group::class)->relation("Members")->Count(); // 0
// Get number of Members linked to the Administrator Group:
echo \SilverStripe\Security\Group::get()->byID(2)->Members()->Count(); // 1 or more
@maxime-rainville
Copy link
Contributor

I've confirmed the bug by running @JorisDebonnet's sample code.

I've tried creating a normal user and adding the to the administrator (as opposed to using the default admin) and I still get an empty list.

I think the problems is specific to the Members relation somehow. If I switch to the Roles many-many-relation, I get the expected results.

@maxime-rainville
Copy link
Contributor

Problem is probably related to the Groups::Member() method.

Groups can have SubGroups. So we override the Members relation on groups so that members of child groups get return as well.

@sminnee sminnee changed the title DataList::relation does not seem to work [ORM] DataList::relation does not seem to work Oct 7, 2018
@sminnee sminnee changed the title [ORM] DataList::relation does not seem to work [ORM] DataList::relation doesn't work for Group.Memberss Nov 9, 2018
@sminnee
Copy link
Member

sminnee commented Mar 8, 2019

Yeah the relation() method assumes a "normal" relation to some extent, which Members is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants