This repository was archived by the owner on Mar 1, 2018. It is now read-only.
Minor correction to docs, fix for sql error, fix to preSelect dql callback#10
Open
benlumley wants to merge 3 commits intocaefer:masterfrom
Open
Minor correction to docs, fix for sql error, fix to preSelect dql callback#10benlumley wants to merge 3 commits intocaefer:masterfrom
benlumley wants to merge 3 commits intocaefer:masterfrom
Conversation
… filtering comments by blog post). Error was relating to incorrect parameter count. After some trial and error, passing 0 (suppresses limit subquery) to getSqlQuery as it's second argument fixes this. I've seen no side effects yet ... should be ok, as i think the aim is to make doctrine create the query, the limit subquery isn't needed.
…ener to fix two bugs, as detailed below.
Suppose you have:
Categories, which have many Posts. You also have an Image object.
Both "Category" and "Post" are LooselyCoupled to "Image".
If you try to do a query like this:
Doctrine::getTable('Category')->createQuery('c')
->leftJoin('c.Images ci')
->leftJoin('c.Post p')
->leftJoin('p.Images pi');
things go a bit wrong - key bit is that the same LooselyCoupleable component (Image) is joined twice to two different components (Post and Category).
We end up with SQL that looks like:
...
FROM category c
LEFT JOIN post p ON c.id = p.category_id
LEFT JOIN image i ON c.id = i.obj_pk AND (i.obj_type = "Category") AND (i.obj_type = "Category")
LEFT JOIN image i2 ON p.id = i2.obj_pk AND (i2.obj_type = "Category") AND (i2.obj_type = "Category")
...
Two things wrong here:
1. The obj_type is always the root alias/component of the query (I think it goes even more wrong if the root component is not part of a LooselyCoupled relationship)
2. Inconsequential, but annoying - the obj_type condition is added twice to each join.
This patch makes it create the expected:
...
FROM category c
LEFT JOIN Post p ON c.id = p.category_id
LEFT JOIN image i ON c.id = i.obj_pk AND (i.obj_type = "Category")
LEFT JOIN image i2 ON p.id = i2.obj_pk AND (i2.obj_type = "Post")
...
Contributor
Author
|
Added additional commit - see commit log for details, fixes issue with preDQLSelect listener. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.