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

StandardRelatedDataService not working for complex relations #11067

Open
sb-relaxt-at opened this issue Nov 24, 2023 · 2 comments
Open

StandardRelatedDataService not working for complex relations #11067

sb-relaxt-at opened this issue Nov 24, 2023 · 2 comments

Comments

@sb-relaxt-at
Copy link
Contributor

sb-relaxt-at commented Nov 24, 2023

Affected Version

Any version including StandardRelatedDataService (Silverstripe 4 and 5).

Description

There are multiple cases in which the StandardRelatedDataService does not work (Undefined index) or return wrong results. I do understand that the DataService is marked for internal use and might be not intended for use with other DataObjects than Files. Nevertheless these issues also occur if Files are used in complex relationships.

Case 1

There is no support for polymorphic relations besides the Parent relation. If polymorphic relations are involved there will be no filtering by class, resulting in wrong related data returned.

if ($componentIDField === 'ParentID' && $record->ParentClass) {

$where .= sprintf(' AND "ParentClass" = %s', $this->prepareClassNameLiteral(get_class($record)));

if (count(array_keys($row ?? [])) === 2 && isset($row['ParentClass']) && isset($row['ParentID'])) {

Case 2

Given the the following DataObject structure for a Many-many-through Relation between X and Y by class B:

A:
  has_one:
    x: X
B: #extends A
  has_one:
    y: Y

The service won't be able to find the configuration for x as it uses the uninherited config of B which does not include the relation to X, resulting in an Undefined index see:

return $this->config[$lowercaseThroughClass]['has_one'][$toComponent];

Edit: Fixed a wrong relation in the example.

@sb-relaxt-at sb-relaxt-at changed the title StandardRelatedDataService not working for generic DataObjects StandardRelatedDataService not working for complex relations Nov 24, 2023
@emteknetnz
Copy link
Member

Case 1 will be fixed in 5.2.0 with this PR - #11107

@sb-relaxt-at
Copy link
Contributor Author

@emteknetnz I am not sure that your PR addresses all references to Parent in StandardRelatedDataService, I suppose there are at least four of them.

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