Skip to content

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

Merged
merged 2 commits into from
Nov 12, 2015

Conversation

teohhanhui
Copy link
Contributor

  • AbstractFilter
  • SearchFilter
  • DateFilter
  • OrderFilter
  • Tests (Thanks @vincentchalamon)

I'm targeting #83


foreach ($propertyParts['associations'] as $association) {
$alias = sprintf('%s_%s', self::DQL_NAMESPACE, $association);
$queryBuilder->join(sprintf('%s.%s', $parentAlias, $association), $alias);
Copy link
Contributor

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?

Copy link
Contributor Author

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).

Copy link
Contributor

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.

@theofidry
Copy link
Contributor

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.

@teohhanhui teohhanhui force-pushed the filter_nested branch 6 times, most recently from 1ad2d44 to d4eeca5 Compare August 27, 2015 12:35
@teohhanhui teohhanhui changed the title [WIP] Doctrine filters: Allow nested properties (across relations) Doctrine filters: Allow nested properties (across relations) Aug 27, 2015
@teohhanhui
Copy link
Contributor Author

@theofidry Would you like to help write some new tests?

@dunglas @sroze This is ready for review.

*
* @return bool
*/
private function useOutputWalkers(QueryBuilder $queryBuilder)
Copy link
Contributor Author

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?

Copy link
Contributor

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 :)

Copy link
Member

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?

Copy link
Contributor Author

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dunglas I too don't get why this should be in another place, when it's specific to Doctrine pagination. But then again I'm not sure I can understand very well the other strong opinions of @sroze

@theofidry
Copy link
Contributor

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(
Copy link
Contributor

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

@sroze sroze mentioned this pull request Aug 31, 2015
@teohhanhui teohhanhui force-pushed the filter_nested branch 4 times, most recently from 6200e1d to 9ef0887 Compare September 1, 2015 10:35
*
* @return string
*/
public static function getJoinRelationship(Join $join)
Copy link
Contributor Author

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.

@dunglas
Copy link
Member

dunglas commented Oct 4, 2015

@vincentchalamon it's the PR I was talking about.

*
* @return ClassMetadata
*/
protected function getNestedMetadata(ResourceInterface $resource, $associations)
Copy link
Contributor

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)

@theofidry
Copy link
Contributor

@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)

@teohhanhui
Copy link
Contributor Author

@dunglas This is in master.

*
* @return array
*/
public static function parseRequestParams($source)
Copy link
Contributor

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.

@sroze
Copy link
Contributor

sroze commented Oct 23, 2015

I'm okay to merge the PR without the optimisation of the filters, but not with these 2 classes RequestUtils and QueryUtils. Please find a better name for them, that's all I want, even I think that if we are introducing this kind of classes means there's something wrong in our design (might be from before your PR).

@teohhanhui
Copy link
Contributor Author

@sroze What do you have in mind?

@theofidry
Copy link
Contributor

I think that if we are introducing this kind of classes means there's something wrong in our design (might be from before your PR).

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.

@dunglas dunglas mentioned this pull request Oct 26, 2015
2 tasks
@@ -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:
Copy link
Member

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?

Copy link
Contributor

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

@vincentchalamon
Copy link
Contributor

Fix in teohhanhui#4

@bwegrzyn
Copy link
Contributor

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.

teohhanhui and others added 2 commits November 12, 2015 14:58
- Fix from GitHub comments
- Rename Request & Query factory class
- Fix request get content
@teohhanhui
Copy link
Contributor Author

Commits from @vincentchalamon merged and squashed.

dunglas added a commit that referenced this pull request Nov 12, 2015
Doctrine filters: Allow nested properties (across relations)
@dunglas dunglas merged commit 1101920 into api-platform:master Nov 12, 2015
@dunglas
Copy link
Member

dunglas commented Nov 12, 2015

Thank you very much for this hard work @teohhanhui and @vincentchalamon

@teohhanhui teohhanhui deleted the filter_nested branch November 12, 2015 07:08
@vincentchalamon
Copy link
Contributor

Thanks @dunglas. Can you release it soon ?

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

Successfully merging this pull request may close these issues.

7 participants