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 8130195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:37:08+00:00 2026-06-06T08:37:08+00:00

I have a table A which references table B. edit: Database engine used is

  • 0

I have a table A which references table B.

edit: Database engine used is MyISAM.

Doctrine mapping works like a charm, except when I have non valid case in the DB where referenced ID in table A does not really exist in table B.

So when you execute this code:

$objectB = $objectA->getObjectB();//with lazy load

you actually get $objectB proxy object which is not null. So !empty($objectB) will pass.

And when you try to access any property of $objectB, like:

$objectB->getName();

you get Entity not found exception. There is not way you can predict in your code that $objectB actually does not exist and that there’s no Name property for $objectB.

$objectB should actually be set to null but that is not happening.

Hibernate has actually mapping property not-found=ignore which sets missing object to NULL instead of setting it to Proxy object. Does Doctrine has anything similar?

PS. Of course you can always catch the Entity not found exception, and play around with that. Or you can map the actual objectB_ID field at the table A, but those are not 100% clean solutions.

I hope someone has an answer.

Thank You

  • 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-06-06T08:37:11+00:00Added an answer on June 6, 2026 at 8:37 am

    except when I have non valid case in the DB where referenced ID in table A does not really exist in table B

    IMO this is a case of garbage in, garbage out. If you have schema where TableA may or may not have a row in TableB, you should implement a FK constraint on TableB, so that if a row is deleted from TableB, any rows in TableA referencing deleted rows will have their values changed to null.

    If you really wanted to move forward on your proposed schema implementation, you could try doing:

    $rowExists = ($objectA->getObjectB()->getId() > 0) ? true : false;
    

    This of course assumes you have an id column on tableB and that it is unsigned.

    — Update —

    try {
        $objectB = $objectA->getObjectB();
    } catch (Exception $e) {
        $objectB = null;
    }
    
    if ($objectB instanceof ClassB) {
        // Do work
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a table which references itself and I need to be able
I have table which contains double values stored in mysql database ...I need to
I want to have a database table that keeps data with revision history (like
Situation: In my database I have a table in which records may reference other
So I have a reference table which stores the primary key, description and update
I have table in which I am inserting rows for employee but next time
i have a table which has many fields but i want to get count
I have a table which i want to store all the outputs into one
I have one table which contains events and dates, and another which contains the
I have a table which stores the data related to posts in this format

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.