Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mark Aquino
On Wed, Apr 14, 2021 at 1:19 PM Mike Bayer wrote: > > > On Wed, Apr 14, 2021, at 11:45 AM, Mark Aquino wrote: > > Thanks. I’ll take a stab at this approach. To back up a little bit my main > confusion is around why the association tables aren’t updating as expected. > As I un

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mark Aquino
the additional logic to remove the stranded chains that are left behind but not linked to any test_molecules anymore. Am I doing something differently in my test_molecule configuration that I'm just not seeing? Mark Aquino From: sqlalchemy@googlegroups.com on behalf

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-13 Thread Mark Aquino
Hi Mike, Sorry about the indentations. I'm not sure I understand the changes you made to the script after delete as it removes all test_chains, test_var_regions, and test_const regions that are still referenced by the other test_molecules. The only way I've been able to get the delete to work

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-13 Thread Mark Aquino
I just wanted to clarify, the desire would be for the "test_var_region" and "test_const_region" entities that are linked to other entities to remain untouched and only to have their associations removed from the deleted items. The output from the ORM indicates that the system is actually

Re: [sqlalchemy] can you insert data for a model with a many to many relationship using alembic?

2021-03-10 Thread Mark Aquino
Thanks. I ended up using the models in the alembic file instead of bulk insert mappings. Your point is well taken about the caveats of the model being out of date but in this use case (just seeding the database) there’s no risk. Mark Aquino From: sqlalchemy

Re: [sqlalchemy] Re: Can't delete cascade many-to-many with polymorphic relationships unless using lazy=dynamic

2020-12-18 Thread Mark Aquino
is unable to know how many rows containing the desired type are present when the mixer table contains references to several different classes by using the id shared on the base class. Mark Aquino From: sqlalchemy@googlegroups.com on behalf of Mike Bayer Sent

Re: [sqlalchemy] Re: Can't delete cascade many-to-many with polymorphic relationships unless using lazy=dynamic

2020-12-17 Thread Mark Aquino
the same mixer table, because they all share a primary key with BaseClass (and removing the need to make explicit mixed tables for every subclass). Mark Aquino From: sqlalchemy@googlegroups.com on behalf of Mike Bayer Sent: Thursday, December 17, 2020 7:08:58 PM

Re: [sqlalchemy] ORM AmbiguousForeignKeysErro

2020-09-09 Thread Mark Aquino
It's okay, I misunderstood what to point to in the inherit_condition argument. I pointed it to the right column and it's working now. On Tue, Sep 8, 2020 at 9:37 PM Richard Damon wrote: > On 9/8/20 8:02 PM, Mark Aquino wrote: > > I’m not using that FK for inheritance though. I’m just

Re: [sqlalchemy] ORM AmbiguousForeignKeysErro

2020-09-08 Thread Mark Aquino
So if I’m understanding correctly then the inherit_condition should be the column mapping the subclass to the superclass? In my case TrackedEntity.id == Request.id? Mark Aquino From: sqlalchemy@googlegroups.com on behalf of Mike Bayer Sent: Tuesday, September

Re: [sqlalchemy] ORM AmbiguousForeignKeysErro

2020-09-08 Thread Mark Aquino
I’m not using that FK for inheritance though. I’m just relating one type of tracked entity to another (it’s parent, basically). After I did this it actually broke my code so it didn’t really work (it just temporarily got rid of one error and caused a more complicated one) Mark Aquino

[sqlalchemy] helper function to get and/or update the InstrumentedList from a relationship on a model

2020-08-12 Thread Mark Aquino
I was interested in creating a generic helper function to get the instrumented list associated with a "RelationshipProperty" for a Model, you can get the relationship from inspect(model).mapper.relationships.items(), but the relationship is just the RelationshipProperty object and *not* the

[sqlalchemy] looking for help building relationship that references an intermediate mixer table

2020-03-20 Thread Mark Aquino
I'd like to create a relationship that joins a table linked to a related table on a model: I have a Vessel class, a Well class, and a Batch class. Vessel and Well are related via a FK on Well (well.vessel_id) but Batch is a many to many relationship with Well, e.g. Batch(Base): id =

Re: [sqlalchemy] relationship without using a column value (using table name)?

2020-03-16 Thread Mark Aquino
: > > > > On Mon, Mar 16, 2020, at 1:23 PM, Mark Aquino wrote: > > Unfortunately none of those recipes work for what I'm trying to > accomplish, and the mapper just complains that there is no "unambiguous" > foreign key column to map the two classes. > > N

Re: [sqlalchemy] relationship without using a column value (using table name)?

2020-03-16 Thread Mark Aquino
ying the > "entity_type" table, however all four will store essentially the same > information, just in different formats. > > > > > > > > On Sat, Mar 14, 2020, at 9:55 AM, Mark Aquino wrote: > > Is it possible to create a relationship via the

[sqlalchemy] relationship without using a column value (using table name)?

2020-03-14 Thread Mark Aquino
Is it possible to create a relationship via the table name as the "foreign key"? I tried playing around with the foreign and remote options and tried utilizing what's described here: https://docs.sqlalchemy.org/en/13/orm/join_conditions.html#non-relational-comparisons-materialized-path but I

Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?

2020-02-15 Thread Mark Aquino
“You can use a @property so that when you get back an A or a B object , they seek to return either the column on A or the column on B.“ I believe you’re describing the behavior I currently have, I.e. if I query B then I can get b.visible_id otherwise I get A.visible_id. I see your point about

Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?

2020-02-14 Thread Mark Aquino
e for every child class table, although a.) i dont know if you can do that and b.) it's less desirable to have duplicate values in that column. On Friday, February 14, 2020 at 12:55:47 PM UTC-5, Simon King wrote: > > On Fri, Feb 14, 2020 at 5:35 PM Mark Aquino > wrote: > > > >

Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?

2020-02-14 Thread Mark Aquino
e for every child class table, although a.) i dont know if you can do that and b.) it's less desirable to have duplicate values in that column. On Friday, February 14, 2020 at 12:55:47 PM UTC-5, Simon King wrote: > > On Fri, Feb 14, 2020 at 5:35 PM Mark Aquino > wrote: > > > >

[sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?

2020-02-14 Thread Mark Aquino
I have a polymorphic class structure like this, with a lot of classes extending the parent class. In reality I'm using a Mixin that declares the visible_id column and it's defined with @declared_attr.cascading, but for simplicity: class A(Base): __tablename__ = 'a' id =