Doctrine QueryBuilder table alias

The Doctrine project, best known for its Object Relational Mapper, also includes a database abstraction layer, used by the ORM. This abstraction layer is called DBAL, for DataBase Abstraction Layer.

Quickly after I started using DBAL in some Wikibase components, I got annoyed at how single table single table selects needed to be created. The QueryBuilder has a “from” method, in which one needs to specify the table name. The annoying bit is that you also had to specify a table alias, and then use this alias in the select and where calls as well.

dbal-old

In an hour of free time and several commits I made the parameter optional, enabling one to do the same without having to specify the alias:

dbal-new

This change will be part of the upcoming Doctrine DBAL 2.5.

2 thoughts on “Doctrine QueryBuilder table alias”

  1. I just had question, in your second block code us selected id and name what if you wanted to select all the columns what parameter would u pass the select method. With an alias you just sent the alias u

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.