Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7627931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:31:38+00:00 2026-05-31T05:31:38+00:00

In my application, I have a a number of simple reference/lookup database tables used

  • 0

In my application, I have a a number of simple reference/lookup database tables used for supplying a list of permitted values in a related table.

(You know, a ‘Countries’ table has a list of countries that are permitted in the ‘country’ field of the Address table…)

To keep my data model as lean as possible, I use the “Bill Karwin technique” of skipping the ‘id’ column in the lookup table and just using the actual value as the primary key. That way, you don’t need to do a join to get the value in the main table because it’s already there as the foreign key.

The problem is, Doctrine uses object references for all associations, which means that queries still require joins to the lookup tables — even when the main table already has the values I need.

For example, this query doesn’t work:

$qb->select(array('a.id', 'a.street', 'a.city', 'a.country'))
   ->from('Entity\Address', 'a');

Instead, you have to do this:

$qb->select(array('a.id', 'a.street', 'a.city', 'c.country'))
   ->from('Entity\Address', 'a')
   ->join('a.country', 'c');

Otherwise you get this error: “Invalid PathExpression. Must be a StateFieldPathExpression.”

Add up all the joins needed for lookup tables, and there’s a lot of unnecessary cost in my queries.

Does anyone know a good way to avoid having to perform joins to lookup/reference tables in Doctrine 2?

(P.S. – I’d prefer to avoid using ENUMs, as they’re not supported by Doctrine and have other well-documented disadvantages.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:31:38+00:00Added an answer on May 31, 2026 at 5:31 am

    Yes, this kind of sucks, but I guess they had a good reason for doing it that way.

    You can use the HINT_INCLUDE_META_COLUMNS hint. It will include all the fields in the query result, including foreign keys which are mapped as relations.

    $query = \Doctrine::em()->createQuery($queryString)
        ->setParameters($params)
        ->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, TRUE);
    

    So if your you have a field city_id in the Address table in the db, it will also be outputted in the query result, along with the “standard” City relation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of enums in my application which are used as property
In an ASP.NET application, I have a small number of fairly complex, frequently used
I have a table. The table needs to store a number values about a
I have an application with number of activities. Own Application class is used for
I have an application that connects to a number of SQL Servers for monitoring
I have an application to count the number of access to an object for
I have an application that receives a number of datums that characterize 3 dimensional
I have an application that calls a number stored by the user. Everything works
I have an application that reuses an Activity an unknown number of times. It
I have a C++ application that includes a number of structures with manually controlled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.