I've been trying for hours now but everytime i create a DQL query with a subquery, it seems to add an ORDER BY to the end that should be apart of the subquery even though i haven't explicitly asked for an ORDER BY.
Here's my DQL:
Doctrine_Query::create()
->select('r.*')
->from($table->getTableName() . ' r')
->innerJoin('r.Product p')
->where('r.is_published = 1')
->andWhere('NOT EXISTS (
SELECT pm.product_id
FROM ProductMedia pm
WHERE pm.product_id = p.id
)');
and heres the resulting query:
SELECT r.id AS r__id, r.created_sf_guard_user_id AS r__created_sf_guard_user_id, r.author_id AS r__author_id, r.published_at AS r__published_at, r.teaser_web AS r__teaser_web, r.teaser_newsletter AS r__teaser_newsletter, r.verdict AS r__verdict, r.product_id AS r__product_id, r.award_recommended AS r__award_recommended, r.award_editors_choice AS r__award_editors_choice, r.with_photos_tab AS r__with_photos_tab, r.first_look AS r__first_look, r.review_type AS r__review_type, r.overall_score AS r__overall_score, r.comments_id AS r__comments_id, r.review_price AS r__review_price, r.reviewed_at AS r__reviewed_at, r.adtech_keywords AS r__adtech_keywords, r.last_synced AS r__last_synced, r.standout_url AS r__standout_url, r.show_on_homepage AS r__show_on_homepage, r.best_deals_copy AS r__best_deals_copy, r.preview_to_review_at AS r__preview_to_review_at, r.created_at AS r__created_at, r.updated_at AS r__updated_at, r.is_published AS r__is_published, r.publish_start AS r__publish_start, r.publish_end AS r__publish_end FROM review r INNER JOIN product p ON r.product_id = p.id WHERE (r.is_published = 1 AND (NOT (EXISTS (SELECT p2.product_id AS p2__product_id FROM product_media p2 WHERE (p2.product_id = p.id))))) ORDER BY p2.position ASC
This is very strange behaviour and not sure whats causing it.
Any help is appreciated and if I'm missing anything to help please ask and i'll edit the question.
Thanks.