-
-
Notifications
You must be signed in to change notification settings - Fork 920
Doctrine filters: Allow nested properties (across relations) #242
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
Conversation
|
||
foreach ($propertyParts['associations'] as $association) { | ||
$alias = sprintf('%s_%s', self::DQL_NAMESPACE, $association); | ||
$queryBuilder->join(sprintf('%s.%s', $parentAlias, $association), $alias); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if you got several properties with the same parent you will end up doing the join several times right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean two or more nested properties through the same relation, then yes. But I'm not sure if it'll cause any real issues (will need to test that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember right it throws an error.
Regarding the tests it might be worth to have fixtures specific to features/scenarios. This can be easily achieved with: You can find an example here. |
1ad2d44
to
d4eeca5
Compare
@theofidry Would you like to help write some new tests? |
* | ||
* @return bool | ||
*/ | ||
private function useOutputWalkers(QueryBuilder $queryBuilder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this should belong in Doctrine ORM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in an other place than here yep :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the problem to have it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought it could be useful in Doctrine ORM (of course, that's subject to the opinion of Doctrine maintainers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to see but I'm very busing moving right now :( I'm testing the two libraries for such tests for the first time with theofidry/LoopBackApiBundle#17 and as there is some things in common I think I may help. You're doing something I wished to do for quite some time now so that the least I can do. I'll take a good look tomorrow but can't guarantee anything. |
*/ | ||
public function __construct(RequestStack $requestStack) | ||
{ | ||
public function __construct( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep the parameters on the same line
6200e1d
to
9ef0887
Compare
* | ||
* @return string | ||
*/ | ||
public static function getJoinRelationship(Join $join) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sroze #242 (diff) has been moved here but remains unresolved.
@vincentchalamon it's the PR I was talking about. |
* | ||
* @return ClassMetadata | ||
*/ | ||
protected function getNestedMetadata(ResourceInterface $resource, $associations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function getNestedMetadata(ResourceInterface $resource, array $associations)
@dunglas to be fair it will require a good amount of work, besides I didn't finished on my end and is not really available either so if we wish to wait it's gonna take another couple of weeks (I'm not saying we should merge this now, but just want to make sure you're taking that into account) |
@dunglas This is in |
* | ||
* @return array | ||
*/ | ||
public static function parseRequestParams($source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is never used outside of that class so can be private.
I'm okay to merge the PR without the optimisation of the filters, but not with these 2 classes |
@sroze What do you have in mind? |
Too me it just looks like the strategy to extract values from the request and the logic to construct our queries have become more complex and should now be dedicated classes. It made sense like it was before as there is nothing wrong with trying to keep things simple, but as the complexity grow a lot with this filter, it calls for some change. |
@@ -10,7 +10,7 @@ Feature: Date filter on collections | |||
Then the response status code should be 200 | |||
And the response should be in JSON | |||
And the header "Content-Type" should be equal to "application/ld+json" | |||
And the JSON should be equal to: | |||
And the JSON should be valid according to this schema: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of using a JSON Schema instead of raw values is great but I what is the interest here has the schema isn't provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer using this method cause when I update configuration, I need to update every feature file about schema. There is no need on it as scenario just need to check configuration. Full schema is already tested on features/crud.feature
Fix in teohhanhui#4 |
4650775
to
2cc6f44
Compare
Just wanted to leave a +1 to show interest in this change. We currently have to issue 3 API requests for something that really should be doable with 1. Can't wait to try out these changes when they are merged. |
0b38817
to
4481c6d
Compare
Commits from @vincentchalamon merged and squashed. |
Doctrine filters: Allow nested properties (across relations)
Thank you very much for this hard work @teohhanhui and @vincentchalamon |
Thanks @dunglas. Can you release it soon ? |
I'm targeting #83