Re: [sqlalchemy] Soft Delete Pattern

2023-07-03 Thread Andrew Martin
This is awesome! Thank you, Mike! -andrew On Monday, July 3, 2023 at 11:05:28 PM UTC-5 Mike Bayer wrote: > this is a major area of functionality that begins with the > "with_loader_criteria" feature: > https://docs.sqlalchemy.org/en/20/orm/queryguide/api.html#sqlalchemy.orm.with_loader_criter

Re: [sqlalchemy] Soft Delete Pattern

2023-07-03 Thread Mike Bayer
this is a major area of functionality that begins with the "with_loader_criteria" feature: https://docs.sqlalchemy.org/en/20/orm/queryguide/api.html#sqlalchemy.orm.with_loader_criteria integration to make the criteria automatic follows at https://docs.sqlalchemy.org/en/20/orm/session_events.htm

[sqlalchemy] Soft Delete Pattern

2023-07-03 Thread Andrew Martin
Hello, I have a base class I tend to use that includes a Boolean is_deleted field so that pretty much every object has that available. Is there a good pattern for setting a filter on these objects that automatically adds a WHERE is_deleted = 'false'? Or does that just have to be added as a fil

Re: [sqlalchemy] Should I use a surrogate primary key on an Association Object pattern?

2023-07-03 Thread 'Michael Mulqueen' via sqlalchemy
Hi Pierre, This isn't an official answer, I'm just a long time user of SQLAlchemy. Either way should work fine. The association object is driven by the columns on the association table being FKs, whether or not they're part of a PK isn't relevant. I've used both ways. In my experience, an artifi

[sqlalchemy] Should I use a surrogate primary key on an Association Object pattern?

2023-07-03 Thread Pierre Massé
Dear all, I am currently reworking a bit of my model and stumbled into this question, which I think mainly has opinionated answers - but I would like to have some insight regarding SQLAlchemy usage or preferences. I have a situation where I am in the exact same case like the one described in the

Re: [sqlalchemy] Left join and nested inner join

2023-07-03 Thread Mike Bayer
use the join construct directly from sqlalchemy.orm import join stmt = select(A).outerjoin(join(B, C), A.id == B.a_id) On Mon, Jul 3, 2023, at 8:29 AM, Michael Ekoka wrote: > > Hi, I'm looking for the SQLAlchemy equivalent to the query > > SELECT * > FROM a > LEFT OUTER JOIN (b INNER JOIN

[sqlalchemy] Left join and nested inner join

2023-07-03 Thread Michael Ekoka
Hi, I'm looking for the SQLAlchemy equivalent to the query SELECT * FROM a LEFT OUTER JOIN (b INNER JOIN c ON b.id = c.b_id) ON a.id = b.a_id Related: https://stackoverflow.com/a/56815807/56974 https://stackoverflow.com/questions/25514160/nested-joins-in-sqlalchemy Table "b" and "c" are joi