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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:16:53+00:00 2026-06-03T06:16:53+00:00

I am storing a bunch of patent data in a MySQL database and interacting

  • 0

I am storing a bunch of patent data in a MySQL database and interacting with it via SQLAlchemy. I have a collection inside the Patent class that represents the list of assignees (the companies that were assigned the patent):

assignees = relationship('Company', secondary=patent_company_table, backref='patents')

I am processing some of the objects stored in the database and for a Patent object p, I want to delete some assignee a (a Company object) from p‘s assignee list. Based off of http://docs.sqlalchemy.org/en/latest/orm/session.html#deleting-from-collections , it seems that calling s.delete(a) will actually delete the Company object a. I simply want to remove assignee a from the list of assignees for p (i.e. remove a row in the patent_company_table), NOT actually delete the Company object, because a might be in another Patent object’s list of assignees.

I tried creating a new list new_assignees that only includes the assignees from p besides a and then called:

p.assignees = new_assignees
s.add(p)

This unfortunately does not actually mark p as dirty, so I assume it would not affect the database.

Do you have any suggestions for how to remove an object from the collection, deleting the row in the patent_company_table as opposed to deleting the object from the Company table?

Thank you.

UPDATE

Here is a snippet of the code:

assignees = patent.assignees
for assignee in assignees:
    if assignee in duplicate_company_to_default:
        patent.assignees.remove(assignee)
        default_company = duplicate_company_to_default[assignee]
        if default_company not in assignees:
            added_patent_count += 1
            patent.assignees.append(default_company)

After looping through all of the patents, added_patent_count = 983672 but there are no objects in session.dirty(). Do I need to add manually to the session after modifying via append or remove?

  • 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-03T06:16:54+00:00Added an answer on June 3, 2026 at 6:16 am

    SQLAlchemy collections support list-like append/remove operations.

    p.assignees.remove(c)
    

    This should remove c form p.assignees without deleting c from database.

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

Sidebar

Related Questions

I am storing a bunch of user ID's inside of a mySQL database along
I have a MySQL database in which I am storing a bunch of textual
I have a bunch of data that I'm pulling into my application which frankly
I have some code that changes a value of some data within my database
I have a bunch of string with special escape codes that I want to
I have a large string in a variable that includes a whole bunch of
I am thinking of storing bunch of data in XML files. Each file will
I'm storing a bunch of realtime data in redis. I'm setting a TTL of
I'm making a java application that is going to be storing a bunch of
Here is my problem. I have a bunch of Configuration classes that get serialized

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.