Skip to content
This repository was archived by the owner on Mar 1, 2018. It is now read-only.

Conversation

@benlumley
Copy link
Contributor

No description provided.

… 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")
...
@benlumley
Copy link
Contributor Author

Added additional commit - see commit log for details, fixes issue with preDQLSelect listener.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant