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 = <some-contract>
permission = <some-permission>

contract.permissions.remove(permission)

https://docs.sqlalchemy.org/en/13/orm/basic_relationships.html#deleting-rows-from-the-many-to-many-table

(note that accessing "contract.permissions" will load all the permissions
for that contract from the database, which might be inefficient depending
on your application)

Hope that helps,

Simon

On Fri, May 29, 2020 at 12:38 PM Mo Hus <teehussai...@gmail.com> wrote:

> 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 entry as shown on line one in database,
>> i want to be able to remove it from my database. (This entry is unique so
>> can only appear once)
>>
>> I have tried PermissionEntity.query.get(contract_id) and
>> PermissionEntity.query.get(permission_id) but doesnt seem to be working
>> as Its not stored in a permission entity.. My relationship does not have an
>> entity. the table i have provided a picture for has a relationship with
>> permissions table and contracts table..
>>
>> --
> 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.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/aac681c3-1a8f-4f99-9d0c-31ab8350518e%40googlegroups.com
> <https://groups.google.com/d/msgid/sqlalchemy/aac681c3-1a8f-4f99-9d0c-31ab8350518e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexe5ZW0stWL0PUyu_mLOTt5XQNctgYmDGyArky6PGhE1Aw%40mail.gmail.com.

Reply via email to