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] this table does not have any entities but has foreign keys which gets data from the two table mentioned above... What I am trying to do is send a query to this table and delete an entry if it exists and i am doing this by the following: result = db.session.query(PermissionEntity).filter(and_([PermissionEntity.contract_id == contract_id, PermissionEntity.permission_id == permission_id]).first() for i in result: i.remove() db.session.commit() Of course this will not work as permission entity has no relationship with permission_contract.. please advice best approach as im new to this? thanks On Thursday, May 28, 2020 at 4:44:31 PM UTC+1, Jonathan Vanasco wrote: > > > `.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 = session.query(VersionedFoo).get((5, 10)) > > or > > my_object = query.get((5, 10)) > > > > If you have another primary key, you'd have to filter: > > > some_object = > session.query(PermissionEntity).filter(PermissionEntity.permission_id==2, > PermissionEntity.contract_id==2).first() > > > or > > some_object = session.query(PermissionEntity).filter_by(permission_id==2, > contract_id==2).first() > > > > > On Thursday, May 28, 2020 at 11:15:38 AM UTC-4, Tanjil Hussain 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/cc6ea4ce-7033-4fb9-af7b-44daea20fd22%40googlegroups.com.