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

[BREAKING] Fix empty param bag #82

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Mohammad-Alavi
Copy link
Contributor

@Mohammad-Alavi Mohammad-Alavi commented Dec 6, 2024

Notes

Summary

This PR addresses #49 and #62, both of which were caused by the changes introduced in #39.

The issue occurs when using the withResourceName method or setting the resource name in any other way, causing the include parameters to be empty. This problem is clearly described in #62.

More Context

In the use case described in #38, if the data returned by Country differs depending on the context (e.g., in the Portfolio context vs. other contexts), it indicates that a different or new transformer should be used for each context. This is precisely what transformers and includes are designed for: to return different data based on context.

If you need to return different data based on context, it is still possible to do so, as demonstrated in the test case.

resolve #49
resolve #62

this test demonstrates that scopes can be accessed in the transformers
Comment on lines +25 to +31
if ($parentScope === 'author') {
$data['called_by_author'] = 'indeed!';
}

if ($parentScope === 'books') {
$data['called_by_book'] = 'yes!';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see, we are returnning different fields based on the context that we are in.
In the author context we return, called_by_author field, and
In the books context we return, called_by_book field.
It seems this is the reult that #39 wanted to achiev.

@@ -405,7 +405,7 @@ public function createData()
$this->manager->parseFieldsets($this->fieldsets);
}

return $this->manager->createData($this->getResource(), $this->resourceName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix.
The rest are just tests 😬

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