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

2020-05-30 Thread Jonathan Vanasco
If I had time to respond yesterday, I would have said the same thing as Simon. Your database model leverages two separate parts of SQLAlchemy: * SqlAlchemy ORM (Left side of the docs https://docs.sqlalchemy.org/en/13/ ) * SqlAlchemy Core (Right side of the docs https://docs.sqlalchemy.org/en/13/

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

2020-05-29 Thread Mo Hus
[image: Capture.PNG] In regards to your question..I want to remove the whole relationship for example.. the whole first row as shown in the picture: On Friday, May 29, 2020 at 10:21:44 PM UTC+1, Mo Hus wrote: > > Hey Simon , permissions has only relationship with permission_contract and > cont

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

2020-05-29 Thread Mo Hus
Hey Simon , permissions has only relationship with permission_contract and contract only has relationship with permission_contract ...I want to be able to delete the relationship from permission_contract ... For example, in my permissions_contract, I may have permission_id = 1 which is the id ta

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

2020-05-29 Thread Simon King
It looks like you've got a many-to-many relationship between Contract and Permission, and you want to remove a Permission from a Contract (or vice versa). Is that right? If so, you can do something like this: contract = permission = contract.permissions.remove(permission) https://docs.sqlalch

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

2020-05-29 Thread Mo Hus
Hey Jonathan, any luck? thanks On Thursday, May 28, 2020 at 4:15:38 PM UTC+1, Mo Hus wrote: > > [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

[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 code

[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 contra

[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 Va

[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 http://s

[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 Verifiabl

[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 description

[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: Capture.PNG

[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