QueryBuilder::addCriteria improvements #584

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants
Contributor

chEbba commented Feb 19, 2013

  1. Fix problem with different comparisons on the same field in QueryExpressonVisitor (now index value is added).
  2. Add criteria field aliasing. Usually oject criteria has "filed = value" notation while DQL has "alias.field = value".
    First level fields are added with alias, second+ level fields (object.field, parent.object.field) are truncated to the second level (object.field) without alias. Alias map can be implemented in future.

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2305

Owner

beberlei commented Feb 19, 2013

I don't like that the visitor gets all the additional code, this is not really his responsibility.

Contributor

chEbba commented Feb 20, 2013

I don't see a good way to implement this features outside. Parameter and alias handling require visit all expressions.

The visitor seems to be at least partially responsible here. All of the expressions need to be visited to add the alias in the WHERE expression. The visitor was already doing this.

However, with this implementation, the visitor gains the now:

  • Tracks aliases
  • Uses/generates the aliases in ordering (it didn't do anything with the orderings before)
  • Uses a more sophisticated method of tracking parameter names.

Those three things can be can be corrected. What would be the acceptable solution here?

  • Shift ordering code outside the visitor? (back to the QueryBuilder)
  • Simplify parameter name generation? (Keep it in the vistor or move it to the QueryBuilder or another Object?)
  • Shift aliasing outside the visitor? (to the the QueryBuilder or some other object?)
  • Something else?
Contributor

chEbba commented May 4, 2013

This PR can be splitted into 2 parts like described in annotation:

  1. Parameter name generation to fix an issue with several conditaional field expressions. This part should be done inside visitor otherwise it will require a complicated logic to handle parameter placeholders outside.
  2. Aliasing. Aliases are applied to where expression fields and ordering fields. It can be moved outside but QB where expression will have to be revisited.
  3. If just ordering logic is moved to QB than alias name generation will be shared between visitor and QB (as order fields should have same names)

The only way to break the logic i see is to create independent FieldAliasVisitor for Criteria -> Criteria converting
This Visitor can be added to the doctrine-common.

@beberlei What do you think?

Contributor

chEbba commented Jul 19, 2013

@beberlei Any news? I can remove field alias from this PR and just save the parameter bugfix, which can be applied for 2.4

Contributor

mnapoli commented Sep 17, 2013

ping @beberlei it would be great to either merge this, or find an alternative

Criteria still can't be used on the QueryBuilder in 2.4.

We use it to implement Domain Driven Design, in which a Repository behaves like an in-memory collection. Criterias are supposed to be an abstraction for filtering collections, but right now it's only usable with ArrayCollections, so it kind of defeat the purpose of the abstraction.

Owner

beberlei commented Jan 3, 2014

I merged a fix for this by into master.

beberlei closed this Jan 3, 2014

Owner

beberlei commented Jan 3, 2014

See 35a62e9

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