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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:16:11+00:00 2026-05-15T01:16:11+00:00

I have a many-to-many relationship defined in my Symfony (using doctrine) project between Orders

  • 0

I have a many-to-many relationship defined in my Symfony (using doctrine) project between Orders and Upgrades (an Order can be associated with zero or more Upgrades, and an Upgrade can apply to zero or more Orders).

# schema.yml

Order:
  columns:
    order_id: {...}
  relations:
    Upgrades:
      class: Upgrade
      local: order_id
      foreign: upgrade_id
      refClass: OrderUpgrade

Upgrade:
  columns:
    upgrade_id: {...}
  relations:
    Orders:
      class: Order
      local: upgrade_id
      foreign: order_id
      refClass: OrderUpgrade

OrderUpgrade:
  columns:
    order_id: {...}
    upgrade_id: {...}

I want to set up delete cascade behavior so that if I delete an Order or an Upgrade, all of the related OrderUpgrades are deleted. Where do I put onDelete: CASCADE? Usually I would put it at the end of the relations section, but that would seem to imply in this case that deleting Orders would cascade to delete Upgrades. Is Symfony + Doctrine smart enough to know what I’m wanting if I put onDelete: CASCADE in the above relations sections of schema.yml?

  • 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-15T01:16:11+00:00Added an answer on May 15, 2026 at 1:16 am

    After much trial and error, the only way I was able to get it to work was to follow the suggestion in Jestep’s comment and move the relationship definitions including onDelete: CASCADE to the linking table, so in the end it looks like this and behaves how I want it to (deletes cascade from Order to OrderUpgrade, and from Upgrade to OrderUpgrade):

    # schema.yml
    
    Order:
      columns:
        order_id: {...}
    
    Upgrade:
      columns:
        upgrade_id: {...}
    
    OrderUpgrade:
      columns:
        order_id: { type: integer, notnull: true, primary: true }
        upgrade_id: { type: integer, notnull: true, primary: true }
      relations:
        Order:
          onDelete: CASCADE
        Upgrade:
          onDelete: CASCADE
    

    I must say I’m got a bit overwhelmed with all of the different Doctrine Many-to-Many YML examples out there on the internet, each with the relations in slightly different places. A frustrating experience.

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

Sidebar

Related Questions

I have a many-to-many relationship defined between two entities using an association table and
I am using nHibernate for db persistence. I have a one-to-many relationship defined between
Let's say I have many-to-many relationship (using the ActiveRecord attribute HasAndBelongsToMany) between Posts and
I have defined a many-to-many relationship between my two entity classes User and Permission.
I have a one to many relationship between two tables. The many table contains
I have two entities Foo and Bar with a Many to Many relationship between
Preface: I have two entities defined as a one-to-many relationship: A <<-------> B. B's
I am trying to define a one to many relationship between Category and Project
I have the following tables in my database that have a many-to-many relationship, which
I have a parent object which has a one to many relationship with an

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.