[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Tanjil Hussain
contract entity: from api.extensions import db from sqlalchemy.sql import expression contracts_users = db.Table("contracts_users", db.Column("contract_id" , db.Integer, db.ForeignKey( "contracts.id"), primary_key=True),

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Jonathan Vanasco
What is the code for PermissionEntity, ContractEntity, and the joining table? it will look like this https://docs.sqlalchemy.org/en/13/orm/basic_relationships.html#one-to-many -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example

Re: [sqlalchemy] Cascade child updates onto the parent

2020-05-28 Thread Colton Allen
Perfect. That's exactly what I ended up doing. I added events (after_insert/update/delete) for each backref. For each has-many relationship (through a secondary table) I had to consider the fact that the parent model would exist in session.dirty but not trigger the "onupdate" action on the

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Tanjil Hussain
This is my function but it does not do anything at the moment : def delete_permission_by_contract_id(contract_id, permission_id): # noqa: E501 """Deletes permissions by contract ID Returns all permissions related to a specific contract. # noqa: E501 :param contract_id: ID of

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Tanjil Hussain
Could you please give me an example. sorry im abit confused and new to this.. On Thursday, May 28, 2020 at 6:02:52 PM UTC+1, Tanjil Hussain wrote: > > Hey, what do you mean by this exactly.. sorry im abit confused and new to > this.. > > On Thursday, May 28, 2020 at 5:55:08 PM UTC+1, Jonathan

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Tanjil Hussain
Hey, what do you mean by this exactly.. sorry im abit confused and new to this.. On Thursday, May 28, 2020 at 5:55:08 PM UTC+1, Jonathan Vanasco wrote: > > Sorry, I meant the SqlAlchemy schema. I can't attempt to troubleshoot > code that I can't see. > -- SQLAlchemy - The Python SQL Toolkit

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Jonathan Vanasco
Sorry, I meant the SqlAlchemy schema. I can't attempt to troubleshoot code that I can't see. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Tanjil Hussain
permission_contract: [image: Capture.PNG] permissions: [image: Capture2.PNG] contracts: [image: Capture3.PNG] -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and

Re: [sqlalchemy] Cascade child updates onto the parent

2020-05-28 Thread Mike Bayer
On Wed, May 27, 2020, at 3:57 PM, Colton Allen wrote: > Hello, > > I'm trying to automate a backref update. Basically, when a child model is > inserted or updated I want the parent model's "updated_at" column to mutate. > The value should be the approximate time the user-child-model was

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Jonathan Vanasco
can you share your schema for these 3 tables? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Tanjil Hussain
Thanks for the response... I have one table for permissions which has 'PermissionEntity' and another table for contract which has 'ContractsEntity' .. the table I am currently trying to remove my entry from is another table called permission_contract which is shown below: [image:

[sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Jonathan Vanasco
`.get()` returns the corresponding row/object based on the primary key https://docs.sqlalchemy.org/en/13/orm/query.html?highlight=get#sqlalchemy.orm.query.Query.get assuming `PermissionEntity` has a primary key of (permission_id, contact_id), the syntax from the examples would be: some_object

[sqlalchemy] how can i remove an entry from relational database using sqlalchemy in python

2020-05-28 Thread Tanjil Hussain
[image: Capture.PNG] permission_id and contract_id have a relationship in the database How can i using remove a entry for example.. if permission_id = 2 and contract_id = 2 exists in the same entry as shown on line one in database, i want to be able to remove it from my database. (This entry