Oct
2
I’ve stumbled across a weired problem in Symfony, using Doctrine. Whenever I wanted to use a leftJoin, stuff would fail. So, here are some tips to help you pass this problems:
1. Check that the leftJoin is issued like $q->(a.RelationshipName r);
where “a” is the root alias of the query, RelationshipName is the NAME of the relationship defined in the yaml file of the database.
2. Make sure you use the actual relationship name from the yaml DB schema, and not the class name or something else. For instance, let’s say you have 2 classes: MysiteArticle and MysiteCategory. To fetch articles, you would build your query like: Doctrine_Query::create()->from(’MysiteArticle a’);
But, to fetch articles together with the category, you would do something like:
Doctrine_Query::create()->from(’MysiteArticle a’)->leftJoin(’a.Category c’); if your relationship name is “Category”, in the schema.yml, or Doctrine_Query::create()->from(’MysiteArticle a’)->leftJoin(’a.MysiteCategory c’); if your relationship name is MysiteCategory.
Comments
One Response to “When Doctrine leftJoin fails”
Leave a Reply








I’m trying to do a join that doesn’t have a relationship defined, because if I define that relationship Doctrine adds a constraint that I don’t want. I am finding that for simple things Doctrine is great and a huge time saver, but for other things it just doesn’t work.
Basic idea of what I’m trying to do. I have an object and a rating. ratings are tied to objects and users. Then there is a comment which are tied to users and objects and have an optional rating. so ratings are constrained to users and objects, and can exist without the comment relationship. if I define the relationship on comment to the rating Doctrine adds a constraint to rating requiring that all ratings be associated with a comment. Doesn’t make sense and not at all what I want.