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

  • Home
  • SEARCH
  • 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 8223565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:44:48+00:00 2026-06-07T14:44:48+00:00

While using doctrine, I noticed that, to delete an entity, I need to retrieve

  • 0

While using doctrine, I noticed that, to delete an entity, I need to retrieve that entity by given parameter(name,id etc) and then call the remove method. On the other hand, in query, I can just execute delete query.

So, seems like, using ORM style requires two operation and general sql operation require one operation. That’s why, I am a little confusing, whether we should use delete(or update) operation in ORM? Isn’t it worse in performance? Or Is there anything else I am missing? Can it be done in any other way in ORM style?

  • 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-07T14:44:49+00:00Added an answer on June 7, 2026 at 2:44 pm

    In Doctrine2 you can call the delete on a proxy object, which is not loaded from the database. Just create a “dummy” object, something like:

    $user = $em->getPartialReference('model\User', array('id' => $id));
    $em->remove($user);
    

    It doesn’t require the initial query, but I’m not quite sure if Doctrine still does it internally on flush. I don’t see it in the SqlLog.

    Just to add, I think this is expected behavior of any decent ORM. It deals with objects and relations. It has to know that something exists before deleting it. ORM is not just a query generator. Generally, a native query will always be faster in any ORM. Any ORM adds a layer of abstraction and it takes some time to execute it. It is a typical tradeoff, you get some fancy features and clean code, but loose some on performance.

    EDIT:

    I’m glad it worked out for you. Actually I stumbled on another problem, which made me realize that proxies and partial objects aren’t actually the same thing. Partial objects instance the real model class, and fill it with values you want. After you initialize a partial object lazy-loading doesn’t work on it anymore. So for instance, if you make a partial object with only the id, and want to delete only if another object field satisfies some condition, it will not work, because that other field will always be null.

    On the other hand, proxies do work with lazy-loading, and don’t share the problems that partial objects have. So I would strongly suggest not to use getPartialReference method, instead you can do something like:

    $user = $em->getReference('model\User', $id);
    $em->remove($user);
    

    The getReference method returns the object if it is already loaded or a proxy if it is not. A proxy can lazy-load all the other values if/when you need them. As for your example, they will behave exactly the same, but proxies are surely a better way to go.

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

Sidebar

Related Questions

While using jQuery's autocomplete, I've noticed that characters & and ' are escaped as
I'm using Symfony and Doctrine, and have several many-to-many relations that work fine. But
While using container managed entity bean when is the bean stored to database by
i am new to symfony.i am using symfony1.4 and Doctrine . While adding a
While using the repository module I noticed Attribute and Values in module setting. What
Can I filter out results from an arrayCollection in Doctrine 2 while using lazy
While using Capistrano for deployment every time that I deploy I find that Rails
while using database under MySQL how can i determine my current MySQL version,database name
While using Visual Studio C# Express 2010, I've noticed a small problem; namespaces such
While using @font-face I am facing a problem that is when I am going

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.