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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:56:17+00:00 2026-05-13T15:56:17+00:00

I have doctrine’s softdelete behavior attached to all of my models. Is there a

  • 0

I have doctrine’s softdelete behavior attached to all of my models. Is there a way I can hard delete a particular record?

In cakephp I remember detaching the behavior… deleting the record and then re attaching the behavior.

Is there something similar in symfony/doctrine ? If so then how do I detach a behavior?

Cheers

  • 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-13T15:56:17+00:00Added an answer on May 13, 2026 at 3:56 pm

    Think I’d go for Zed’s way, but for completeness:

    The Event listener method for delete (and select) for the soft delete behaviour contains:

    if ( ! $query->contains($field)) {
       // do the magic stuff to covert the query to respect softdelete
    }
    

    This means that if you explicitly mention the field in the query, it won’t apply the transformation to the query.

    So, if you do:

    $q = Doctrine_Query::create()
    ->delete('Table t')
    ->where('t.id = ? AND t.deleted != 2 ', 1);
    

    it won’t apply the soft delete stuff and will actually delete the record. Note that you can do anything with t.deleted, I’ve just done something that will always be true. The alias (‘t.’) is important too for it to work.

    This trick works for selects too, which is where I’ve normally used it before.

    As I say though, I think its nicer to do:

    $old_dqlc = Doctrine_Manager::getInstance()->getAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS);
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, false);
    $record->delete();
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, $old_dqlc);
    

    In particular, you can still use the delete() method rather than having to manually create the query. The one plus for the query method is that if you have other behaviours attached to the record, they will still be respected.

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

Sidebar

Related Questions

If I have tables in doctrine for user_1, user_2, etc. is there a way
I have some models witch are using Doctrine nestedset feature. I want to add
Whats the way to unit test Doctrine 2 models? I am using it with
I have a hard time navigating through Doctrine's Documentation for the DBAL. I would
I use doctrine 2.1 I have two objects for the same record, one persisted
Hey all, I'm learning Doctrine + Symfony and I may have chosen too complex
Let's say i have two Doctrine entities: Users and Messages Every user can have
I have models that extend Doctrine_Record, and are directly mapped to one specific record
I have several doctrine models that have relationships to other models. Let's call those
Elloo, I have two doctrine entities and am trying to do left join however

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.