[sqlalchemy] relationship, lazy="subquery"

2022-04-13 Thread Siarhei Siarhei
In admin - when editing, you first need to change the author-owner: to another, otherwise an error. sqlalchemy.exc.InvalidRequestError: Can't attach instance ; another instance with key (, (1,), None) is already present in this session. https://github.com/wnesbv/starlette-all models in folders

[sqlalchemy] relationship

2022-04-12 Thread Siarhei Siarhei
raise sa_exc.InvalidRequestError( sqlalchemy.exc.InvalidRequestError: Can't attach instance ; another instance with key (, (1,), None) is already present in this session. # ... class User(Base): __tablename__ = "users" id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(

Re: [sqlalchemy] Relationship backref cascade path

2021-07-24 Thread Mike Bayer
On Sat, Jul 24, 2021, at 5:49 AM, Lele Gaifax wrote: > Hi all, > > I need some clarification on the following RemovedIn20Warning > > "Pet" object is being merged into a Session along the backref cascade path > for relationship "Person.pets"; in SQLAlchemy 2.0, this reverse cascade will >

[sqlalchemy] Relationship backref cascade path

2021-07-24 Thread Lele Gaifax
Hi all, I need some clarification on the following RemovedIn20Warning "Pet" object is being merged into a Session along the backref cascade path for relationship "Person.pets"; in SQLAlchemy 2.0, this reverse cascade will not take place... Does it really means that in SA 2.0 the pattern

Re: [sqlalchemy] Relationship between two models without constraints or cascades

2021-03-14 Thread Mike Bayer
I also intended to mention there's an option that might work here, though im not sure, which is to set passive_deletes='all' on both sides , which disables this "nulling out" operation, not sure if it will go all the way for the primary key columns here but it's worth a try: https://docs.sqlalc

Re: [sqlalchemy] Relationship between two models without constraints or cascades

2021-03-14 Thread Mike Bayer
On Sun, Mar 14, 2021, at 7:49 AM, Jack Matthews wrote: > The database I am trying to maintain is a representation of a configuration > file I have scraped from a network device. I have two models that when both > exist in the configuration are related to each other, but it is also possible > t

[sqlalchemy] Relationship between two models without constraints or cascades

2021-03-14 Thread Jack Matthews
The database I am trying to maintain is a representation of a configuration file I have scraped from a network device. I have two models that when both exist in the configuration are related to each other, but it is also possible that one or the other may not be present. The schemas are included

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-03-01 Thread 'Jonathan Vanasco' via sqlalchemy
"is it better to think of rebuilding medium+ projects for 2.0 while maintaining existing codebases for 1.3? In other words, how much will 2.0 be backward compatible with 1.3?" I am saying the following as a general user, and not a past contributor to this project: As per the Release Status sys

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-03-01 Thread Mike Bayer
On Mon, Mar 1, 2021, at 9:45 AM, Ahmed wrote: >> > I'm not authorized to talk on behalf of F-S but IMO, these options could be > milestones applied in parallel toward migration to 2.0. However, a question > arises here, that you might have already seen, which is: given the major leap > in how

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-03-01 Thread Ahmed
> > yes so, SQLAlchemy 2.0's approach is frankly at odds with the spirit of > Flask-SQLAlchemy.The Query and "dynamic" loaders are staying around > largely so that Flask can come on board, however the patterns in F-S are > pretty much the ones I want to get away from. 2.0's spirit is one wher

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-26 Thread Mike Bayer
On Fri, Feb 26, 2021, at 8:04 AM, Ahmed wrote: > Hi Mike - Thank you for your insights. Actually, this is part of upgrading > Flask-SQLAlchemy library dependency to 1.4.0b3 and eventually 2.0. The > snippet above is extracted from a test case that didn't pass against 1.4.0b3. > > I've checked

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-26 Thread Ahmed
Hi Mike - Thank you for your insights. Actually, this is part of upgrading Flask-SQLAlchemy library dependency to 1.4.0b3 and eventually 2.0. The snippet above is extracted from a test case that didn't pass against 1.4.0b3. I've checked sqlalchemy.orm.with_parent

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-25 Thread Mike Bayer
this will be fixed in https://github.com/sqlalchemy/sqlalchemy/issues/5981 where I've reverted entirely some changes to AppenderQuery that made it work more in 2.0 style. As Query is going to be present in 2.0, "dynamic" relationships will remain also as legacy. They are superseded by explic

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-25 Thread Mike Bayer
this is a bug. however, the Query object is legacy. what is your actual use case? there are better ways to achieve them now. On Thu, Feb 25, 2021, at 3:25 PM, Ahmed wrote: > Hello, > > It seems that SQLAlchemy 1.4.0b3 ignores relationship() query_class > parameter. Here's the snippet tha

[sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-25 Thread Ahmed
Hello, It seems that SQLAlchemy 1.4.0b3 ignores relationship() query_class parameter. Here's the snippet that works with 1.3 but doesn't with 1.4: class Parent(db.Model): __tablename__ = "todo" id = db.Column(db.Integer, primary_key=True) # ... Column mappings children = db.rela

[sqlalchemy] Relationship with 2 intermediary tables

2021-02-07 Thread Dane K Barney
I am trying to create a relationship from one table to another, which involves two intermediary tables. I *think* I need to use the secondaryjoin + secondary arguments to relationship(). But after studying the documentation for a long time, I can't get my head around how these arguments are sup

Re: [sqlalchemy] Relationship Based On Expression

2020-09-09 Thread Bobby Rullo
Wow - thank you so much - that was really above and beyond. There's a lot to digest there so I need to pore it over, but I think I get the general idea. Bobby On Wed, Sep 9, 2020 at 6:10 PM Mike Bayer wrote: > OK what you're trying to do is a little hard , and yes declare_last / > declare_first

Re: [sqlalchemy] Relationship Based On Expression

2020-09-09 Thread Mike Bayer
OK what you're trying to do is a little hard , and yes declare_last / declare_first are useful here, because I just noticed you need to inspect the PK of the local class, not the remote one, so that has to be set up first. So here is a demo based on declare_first, this is the basic idea, eith

Re: [sqlalchemy] Relationship Based On Expression

2020-09-09 Thread Bobby Rullo
Thanks for the reply Mike! I tried to go down the "dynamically add multiple obj_ids" but I could not figure it out. The obvious choice for dynamic stuff is @declared_attr but that only let's me define one thing. How would I do *n* things? Is this a situation where __declare_last__ could help? O

Re: [sqlalchemy] Relationship Based On Expression

2020-09-09 Thread Mike Bayer
On Wed, Sep 9, 2020, at 2:36 PM, Bobby Rullo wrote: > Hi there, > > I'm trying to create a relationship for a Mxin that is agnostic to what the > primary key of the mixed object is. > > Basically we have this: > > class TransitionBase(SurrogatePK, Model): > __abstract__ = True > > o

[sqlalchemy] Relationship Based On Expression

2020-09-09 Thread Bobby Rullo
Hi there, I'm trying to create a relationship for a Mxin that is agnostic to what the primary key of the mixed object is. Basically we have this: class TransitionBase(SurrogatePK, Model): __abstract__ = True obj_id = Column(String, nullable=False, index=True) state = Column(String

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

2020-03-16 Thread Mark Aquino
I guess I could do that: I am using a joined table inheritance schema for most of the classes in my data model (and that base table does have an entity_type_id) but was trying to link a few "entity_type"s to some of the classes that didn't inherit from the base. The difference in the Django mod

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

2020-03-16 Thread Mike Bayer
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. > > Normal referential integrity rules would dictate th

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

2020-03-16 Thread Mark Aquino
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. Normal referential integrity rules would dictate that I create a column on the related class that referred to the e

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

2020-03-14 Thread Mike Bayer
this is called a "Generic foreign key" and it's not really a real relational database pattern. There are a series of examples in https://docs.sqlalchemy.org/en/13/orm/examples.html#module-examples.generic_associations that show four different ways to achieve this pattern, one of which is the "g

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

Re: [sqlalchemy] Relationship through association table

2018-12-28 Thread Mike Bayer
On Fri, Dec 28, 2018 at 9:21 AM Mehdi Gmira wrote: > > I have one example illustrating that A.b.id does not pick up the correct id okey doke, set that all up explicitly as below, will update the example now, thanks for the complete test B_viacd = mapper(B, j, non_primary=True, primary_key=[j.c.b

Re: [sqlalchemy] Relationship through association table

2018-12-28 Thread Mehdi Gmira
I have one example illustrating that A.b.id does not pick up the correct id from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, func, Table, create_engine, join from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload, contains_eager, mapper from sqlalchemy.ext.

Re: [sqlalchemy] Relationship through association table

2018-12-28 Thread Mike Bayer
On Fri, Dec 28, 2018 at 4:24 AM Mehdi Gmira wrote: > > Thanks for the reply. There is something I don't understand in the example: > > B_viacd = mapper(B, j, non_primary=True, properties={ > "b_id": [j.c.b_id, j.c.d_b_id], > "d_id": j.c.d_id > }) > > > How Is the mapper supposed to map

Re: [sqlalchemy] Relationship through association table

2018-12-28 Thread Mehdi Gmira
Thanks for the reply. There is something I don't understand in the example: B_viacd = mapper(B, j, non_primary=True, properties={ "b_id": [j.c.b_id, j.c.d_b_id], "d_id": j.c.d_id }) How Is the mapper supposed to map the results of j with the class B ? the statement behind j is: SELE

Re: [sqlalchemy] Relationship through association table

2018-12-27 Thread Mike Bayer
the section at https://docs.sqlalchemy.org/en/latest/orm/join_conditions.html#relationship-to-non-primary-mapper has a recipe for: "when we seek to join from A to B, making use of any number of C, D, etc. in between, however there are also join conditions between A and B directly", I think that's

[sqlalchemy] Relationship through association table

2018-12-27 Thread mgmira
from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, func, Table, create_engine from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload, contains_eager from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() engine = create_engine('sq

[sqlalchemy] Relationship to child with 2 foreginKey from same Parent column

2018-08-22 Thread Alireza Ayin Mehr
Hello, everyone I have a User model and a Conversation model class Conversation(Base): __tablename__ = 'conversations' id = Column(Integer, primary_key=True) user1 = Column(Integer, Foreignusers.id'), unique=False, nullable=False) user2 = Column(Integer, ForeignKey('users.id'), unique=Fals

Re: [sqlalchemy] Relationship to non primary mapper with association proxy

2018-06-03 Thread Ashley Bye
Thanks for this Mike. I've actually changed my model slightly to reduce the complexity, but I'm very grateful for the effort you put into trying to help me out. I'm going to keep this kicking around so I can try and understand what is going on. On Friday, 1 June 2018 19:54:54 UTC+1, Mike Bayer

Re: [sqlalchemy] Relationship to non primary mapper with association proxy

2018-06-01 Thread Mike Bayer
On Thu, May 31, 2018 at 5:43 AM, Ashley Bye wrote: > I'm trying to create a relationship between two tables, but filtered based > on information from an association proxy. This seems to me a bit like a > relationship to a non-primary mapper > (http://docs.sqlalchemy.org/en/latest/orm/join_conditio

[sqlalchemy] Relationship to non primary mapper with association proxy

2018-05-31 Thread Ashley Bye
I'm trying to create a relationship between two tables, but filtered based on information from an association proxy. This seems to me a bit like a relationship to a non-primary mapper (http://docs.sqlalchemy.org/en/latest/orm/join_conditions.html#relationship-to-non-primary-mapper). However, I

Re: [sqlalchemy] Relationship: OrderedDict - errors when None values

2017-11-06 Thread Mike Bayer
On Mon, Nov 6, 2017 at 12:47 PM, Sven wrote: > Hello, > > I'm actually working on an online-game which is already advanced and pretty > consequent. As I explained in a previous mail, my goal is to replace the > save system actually based on Pickle by SQLAlchemy. If it is possible, it > would be be

[sqlalchemy] Relationship: OrderedDict - errors when None values

2017-11-06 Thread Sven
Hello, I'm actually working on an online-game which is already advanced and pretty consequent. As I explained in a previous mail, my goal is to replace the save system actually based on Pickle by SQLAlchemy. If it is possible, it would be better for me to stay with the initial classes organizat

Re: [sqlalchemy] Relationship between objects in different schemas

2016-10-22 Thread Mike Bayer
On 10/22/2016 08:08 AM, Nikola Radovanovic wrote: Hi all, I have a question regarding what will be the best possible way to resolve following scenario: 1. lets say I have table(s) in 'public' schema and multiple 'private' schemes with same table layout 2. each private schema is for separ

[sqlalchemy] Relationship between objects in different schemas

2016-10-22 Thread Nikola Radovanovic
Hi all, I have a question regarding what will be the best possible way to resolve following scenario: 1. lets say I have table(s) in 'public' schema and multiple 'private' schemes with same table layout 2. each private schema is for separate customer, and public contains some data e

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-09 Thread Florian Rüchel
Thanks for the explanation. I don't need a quick fix for my use-case. The problem only happens when writing tests and there I can just build a manual reload when I know the object is expired (I expire it manually on purpose). On 08/09/2016 01:17 AM, Mike Bayer wrote: > > > On 08/08/2016 07:43 AM

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-08 Thread Mike Bayer
On 08/08/2016 07:43 AM, Florian Rüchel wrote: I created a gist that recreates the issue when running SQLAlchemy 1.1.0b3: https://gist.github.com/Javex/41c58b098c1e5736cb2b21c4b6708be3 great test. So this is to do with the lazy loader which is not expecting to see what it's seeing here.b

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-08 Thread Florian Rüchel
I created a gist that recreates the issue when running SQLAlchemy 1.1.0b3: https://gist.github.com/Javex/41c58b098c1e5736cb2b21c4b6708be3 Traceback (most recent call last): File "broken_autojoin.py", line 73, in print('Title: %s' %article.german.title) File "/home/javex/.virtualenvs/mtc

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-07 Thread Mike Bayer
On 08/06/2016 08:03 PM, Florian Rüchel wrote: Following up on this. I have implemented it in my application and it works beautifully when querying for the object. However, while writing tests, I discovered that if the object is expired, it doesn't know how to refresh it. To explain the issue,

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-06 Thread Florian Rüchel
Following up on this. I have implemented it in my application and it works beautifully when querying for the object. However, while writing tests, I discovered that if the object is expired, it doesn't know how to refresh it. To explain the issue, I need to expand my original (simplified) examp

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-04 Thread Florian Rüchel
Awesome idea, thanks for the reply! I ended up combining this approach with the callable_ argument and don't have to explicitly pass the argument now at all. This is a great approach and it is fairly simple as well. Thank you a lot. On Friday, 5 August 2016 00:24:30 UTC+10, Mike Bayer wrote:

Re: [sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-04 Thread Mike Bayer
On 08/04/2016 10:14 AM, Florian Rüchel wrote: I have a relationship that depends on a query time variable to determine the correct join. The use case is request-time localization in a web application. When running the query during a request, I want to determine the locale and only load the tran

[sqlalchemy] Relationship with query time evaluated primaryjoin

2016-08-04 Thread Florian Rüchel
I have a relationship that depends on a query time variable to determine the correct join. The use case is request-time localization in a web application. When running the query during a request, I want to determine the locale and only load the translation for the current language for a given o

Re: [sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-30 Thread bsdz
Yes, that worked - thanks! :) > -- 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 post to this group, send email to sql

Re: [sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-29 Thread Mike Bayer
name the COUNTRY_ID column in lower case in your mapping, all UPPERCASE means case sensitive and it will be quoted "COUNTRY_ID", and not match the case-insensitive country_id name in your actual schema. On 07/29/2016 03:29 PM, bsdz wrote: I did some further checking and realized deeper down

Re: [sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-29 Thread bsdz
I did some further checking and realized deeper down the real issue lies column name case and with column_reflect where I map my column names to lower case. This seems to confuse the ForeignKey function. Here's a complete example with sqlite. Perhaps there's a simple workaround? import sqlalche

Re: [sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-29 Thread Blair Azzopardi
I rechecked everything and I realised that the ForeignKey column is case sensitive. Thanks for your help! On 29 July 2016 at 17:58, Blair Azzopardi wrote: > Interesting. Yes each table was in a different schema in pre-simplified > code and I am using SQL server via pyodbc from Linux. I'll try an

Re: [sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-29 Thread Mike Bayer
On 07/29/2016 12:27 PM, bsdz wrote: Hi I'm trying to use DeferredReflection to encapsulate my data model so that it can easily be instantiated for different environments. However, I am having trouble creating relationships with a NoForeignKeysError being raised. I am guessing it is because the

Re: [sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-29 Thread Blair Azzopardi
Interesting. Yes each table was in a different schema in pre-simplified code and I am using SQL server via pyodbc from Linux. I'll try and get a more complete test case shortly. On 29 Jul 2016 5:53 p.m., "Mike Bayer" wrote: > > > On 07/29/2016 12:27 PM, bsdz wrote: > >> Hi >> >> I'm trying to us

[sqlalchemy] relationship with DeferredReflection raises NoForeignKeysError

2016-07-29 Thread bsdz
Hi I'm trying to use DeferredReflection to encapsulate my data model so that it can easily be instantiated for different environments. However, I am having trouble creating relationships with a NoForeignKeysError being raised. I am guessing it is because the table metadata generation is being

Re: [sqlalchemy] relationship joined to max() on a foreign table - help needed

2016-04-26 Thread Mike Bayer
On 04/26/2016 08:09 AM, Rob Fowler wrote: I have a complete example here: https://gist.github.com/mianos/42cf15928f27cc9dfde9996d2e593e78 Ideas? I am sure it's possible. At the moment I am just using a "orderby desc" on the relationship and using [0] to get the first. this example helps a

[sqlalchemy] relationship joined to max() on a foreign table - help needed

2016-04-26 Thread Rob Fowler
Can anyone help me with this interesting (to me) relationship definition in sqla. I have some already defined data, not by me, that has, for each user, a foreign table of contact numbers, where the highest contact number is the one to use. For example, users: Harry, 1081, and Bob 1082 m

Re: [sqlalchemy] Relationship between two databases

2016-02-23 Thread Thierry Florac
Hi, I don't think that the solution can come from SQLAlchemy. You may have to create a database link between your two databases to be able to query both of them with a single instruction... Best regards, Thierry 2016-02-23 11:43 GMT+01:00 Mehdi : > Hi > Is it possible two have a one-to-many or

[sqlalchemy] Relationship between two databases

2016-02-23 Thread Mehdi
Hi Is it possible two have a one-to-many or many-to-many relationship between two models which they are exist in two different databases? I have two oracle dbs on two different machines on lan. so i've created two engines like: main_engine = create_engine("oracle://user:pass@ip1/sid") entry_engin

Re: [sqlalchemy] relationship between declarative base and automap base

2016-02-19 Thread Mike Bayer
On Fri, Feb 19, 2016 at 7:09 PM, Brian Cherinka wrote: > Hi. > > I have two database schemas, with a table from each I would like to join. > The classes for one schema have been created as explicit declarative Bases, > while the classes for the other were all created via automap Base. I have > a

[sqlalchemy] relationship between declarative base and automap base

2016-02-19 Thread Brian Cherinka
Hi. I have two database schemas, with a table from each I would like to join. The classes for one schema have been created as explicit declarative Bases, while the classes for the other were all created via automap Base. I have a foreign key joining the two tables. Sqlalchemy sees the fore

Re: [sqlalchemy] relationship supersedes the same relationship on inherited mapper can cause dependency issues during flush

2015-06-18 Thread Mike Bayer
On 6/18/15 5:04 PM, Kevin Qiu wrote: Error: SAWarning: Warning: relationship 'staff_obj' on mapper 'Mapper|ProjectApp|PROJECT_APP' supersedes the same relationship on inherited mapper 'Mapper|Application|APPLICATION'; this can cause dependency issues during flush self._check_conflicts()

[sqlalchemy] relationship supersedes the same relationship on inherited mapper can cause dependency issues during flush

2015-06-18 Thread Kevin Qiu
Error: SAWarning: Warning: relationship 'staff_obj' on mapper 'Mapper|ProjectApp|PROJECT_APP' supersedes the same relationship on inherited mapper 'Mapper|Application|APPLICATION'; this can cause dependency issues during flush self._check_conflicts() Application is a parent class which can't

Re: [sqlalchemy] relationship(with lazy="dynamic) different behavior on session.delete() btw. SA 0.9.3 and SA 1.0.4

2015-05-26 Thread Mike Bayer
On 5/26/15 11:18 AM, g wrote: Hi all With SA 1.0.4 I can delete rows that i could not delete with SA 0.9.3 . your code is relying on a bug in 0.9.3 that was "fixed" in 0.9.5 (https://bitbucket.org/zzzeek/sqlalchemy/issue/3060) , but we broke other things at the same time and ultimately it

[sqlalchemy] relationship(with lazy="dynamic) different behavior on session.delete() btw. SA 0.9.3 and SA 1.0.4

2015-05-26 Thread g
Hi all With SA 1.0.4 I can delete rows that i could not delete with SA 0.9.3 . MODEL. Base = declarative_base() class Node(Base): __tablename__ = 'node' id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey('node.id')) data = Column(String(50)) childr

[sqlalchemy] Relationship query trouble

2015-03-13 Thread mallory
Hello -- I'm having some trouble forming a query. I'm using sqlalchemy 0.9.9 with Postgres 9.3. I have 3 classes: Users, Responses, and Questions. Question has a one-to-many relationship to Responses. User has a one-to-many relationship to Responses. I'd like to find all questions that a user h

Re: [sqlalchemy] relationship problem

2015-03-12 Thread Michael Bayer
Julien Cigar wrote: > > Hi Mike, > > Sorry to bother you once with this, but I've re-read all the docs on > the relationships and I want to be sure that I've understand correctly. > > Imagine I have the following "link" table in SQL: > https://gist.github.com/silenius/77d406f8e0c0e26eb38f wi

Re: [sqlalchemy] relationship problem

2015-03-12 Thread Julien Cigar
On Mon, Mar 02, 2015 at 12:15:51PM -0500, Michael Bayer wrote: > > > Julien Cigar wrote: > > > On Sun, Mar 01, 2015 at 01:53:30PM +0100, Julien Cigar wrote: > >> On Fri, Feb 27, 2015 at 11:38:05PM -0500, Michael Bayer wrote: > On Feb 26, 2015, at 5:56 AM, Julien Cigar wrote: > > >>>

Re: [sqlalchemy] Relationship behavior change when switching from reflected to declarative styles; test case included

2015-03-04 Thread Evan James
On Tuesday, March 3, 2015 at 4:41:20 PM UTC-5, Michael Bayer wrote: > > Essentially the issue is likely because the mappings in these two examples > are not equivalent; the reflection based version has Widget.frobnicator > and > Frobnicator.widget communicating with each other through a backref,

Re: [sqlalchemy] Relationship behavior change when switching from reflected to declarative styles; test case included

2015-03-03 Thread Michael Bayer
Evan James wrote: > Hi folks, > > I'm working on a SQLAlchemy-based app where we've decided to make some > infrastructure changes, in particular moving from reflection to declaration > for mapping the models. > > However, we're now running into issues where, after switching to declarative,

[sqlalchemy] Relationship behavior change when switching from reflected to declarative styles; test case included

2015-03-03 Thread Evan James
Hi folks, I'm working on a SQLAlchemy-based app where we've decided to make some infrastructure changes, in particular moving from reflection to declaration for mapping the models. However, we're now running into issues where, after switching to declarative, relationships aren't populated the

Re: [sqlalchemy] relationship problem

2015-03-02 Thread Michael Bayer
Julien Cigar wrote: > On Sun, Mar 01, 2015 at 01:53:30PM +0100, Julien Cigar wrote: >> On Fri, Feb 27, 2015 at 11:38:05PM -0500, Michael Bayer wrote: On Feb 26, 2015, at 5:56 AM, Julien Cigar wrote: > On Wed, Feb 25, 2015 at 06:10:55PM -0500, Michael Bayer wrote: > > >

Re: [sqlalchemy] relationship problem

2015-03-02 Thread Julien Cigar
On Sun, Mar 01, 2015 at 01:53:30PM +0100, Julien Cigar wrote: > On Fri, Feb 27, 2015 at 11:38:05PM -0500, Michael Bayer wrote: > > > > > > > > > On Feb 26, 2015, at 5:56 AM, Julien Cigar wrote: > > > > > >> On Wed, Feb 25, 2015 at 06:10:55PM -0500, Michael Bayer wrote: > > >> > > >> > > >> J

Re: [sqlalchemy] relationship problem

2015-03-01 Thread Julien Cigar
On Fri, Feb 27, 2015 at 11:38:05PM -0500, Michael Bayer wrote: > > > > > On Feb 26, 2015, at 5:56 AM, Julien Cigar wrote: > > > >> On Wed, Feb 25, 2015 at 06:10:55PM -0500, Michael Bayer wrote: > >> > >> > >> Julien Cigar wrote: > >> > On Thu, Feb 19, 2015 at 11:31:10AM -0500, Michael

Re: [sqlalchemy] relationship problem

2015-02-27 Thread Michael Bayer
> On Feb 26, 2015, at 5:56 AM, Julien Cigar wrote: > >> On Wed, Feb 25, 2015 at 06:10:55PM -0500, Michael Bayer wrote: >> >> >> Julien Cigar wrote: >> On Thu, Feb 19, 2015 at 11:31:10AM -0500, Michael Bayer wrote: Julien Cigar wrote: >> On Thu, Feb 19, 2015 at 02:45:43

Re: [sqlalchemy] relationship problem

2015-02-26 Thread Julien Cigar
On Wed, Feb 25, 2015 at 06:10:55PM -0500, Michael Bayer wrote: > > > Julien Cigar wrote: > > > On Thu, Feb 19, 2015 at 11:31:10AM -0500, Michael Bayer wrote: > >> Julien Cigar wrote: > >> > >>> On Thu, Feb 19, 2015 at 02:45:43PM +0100, Julien Cigar wrote: > Hello, > > I'm usin

Re: [sqlalchemy] relationship problem

2015-02-25 Thread Michael Bayer
Julien Cigar wrote: > On Thu, Feb 19, 2015 at 11:31:10AM -0500, Michael Bayer wrote: >> Julien Cigar wrote: >> >>> On Thu, Feb 19, 2015 at 02:45:43PM +0100, Julien Cigar wrote: Hello, I'm using SQLAlchemy 0.9.8 with PostgreSQL and the reflection feature of SQLAlchemy. >>>

Re: [sqlalchemy] relationship problem

2015-02-24 Thread Julien Cigar
On Thu, Feb 19, 2015 at 11:31:10AM -0500, Michael Bayer wrote: > > > Julien Cigar wrote: > > > On Thu, Feb 19, 2015 at 02:45:43PM +0100, Julien Cigar wrote: > >> Hello, > >> > >> I'm using SQLAlchemy 0.9.8 with PostgreSQL and the reflection feature of > >> SQLAlchemy. > >> > >> I have the fol

Re: [sqlalchemy] relationship problem

2015-02-19 Thread Julien Cigar
On Thu, Feb 19, 2015 at 11:31:10AM -0500, Michael Bayer wrote: > > > Julien Cigar wrote: > > > On Thu, Feb 19, 2015 at 02:45:43PM +0100, Julien Cigar wrote: > >> Hello, > >> > >> I'm using SQLAlchemy 0.9.8 with PostgreSQL and the reflection feature of > >> SQLAlchemy. > >> > >> I have the fol

Re: [sqlalchemy] relationship problem

2015-02-19 Thread Michael Bayer
Julien Cigar wrote: > On Thu, Feb 19, 2015 at 02:45:43PM +0100, Julien Cigar wrote: >> Hello, >> >> I'm using SQLAlchemy 0.9.8 with PostgreSQL and the reflection feature of >> SQLAlchemy. >> >> I have the following tables (only relevant parts are show): >> https://gist.github.com/silenius/390

Re: [sqlalchemy] relationship problem

2015-02-19 Thread Julien Cigar
On Thu, Feb 19, 2015 at 02:45:43PM +0100, Julien Cigar wrote: > Hello, > > I'm using SQLAlchemy 0.9.8 with PostgreSQL and the reflection feature of > SQLAlchemy. > > I have the following tables (only relevant parts are show): > https://gist.github.com/silenius/390bb9937490730741f2 > > and the "p

[sqlalchemy] relationship problem

2015-02-19 Thread Julien Cigar
Hello, I'm using SQLAlchemy 0.9.8 with PostgreSQL and the reflection feature of SQLAlchemy. I have the following tables (only relevant parts are show): https://gist.github.com/silenius/390bb9937490730741f2 and the "problematic" mapper is the one of my association object: https://gist.github.com/

Re: [sqlalchemy] relationship to self

2014-12-28 Thread Michael Bayer
Please see http://docs.sqlalchemy.org/en/rel_0_9/orm/self_referential.html for special steps to be taken for adjacency list relationships (your answer is in the very first section of this page). Ed Rahn wrote: > I have the following code: > > class Horse(Base): >__tablename__ = 'horse' >

[sqlalchemy] relationship to self

2014-12-28 Thread Ed Rahn
I have the following code: class Horse(Base): __tablename__ = 'horse' id = Column(Integer, primary_key=True) name = Column(String(150), index=True, unique=True) color = Column(Integer) sex = Column(Integer) foaled = Column(Date) skip = Column(Boolean, default=False)

Re: [sqlalchemy] relationship join with same table twice

2014-12-08 Thread Michael Bayer
you’d use aliased and join twice as: c1 = aliased(Child) c2 = aliased(Child) session.query(Parent).join(c1, Parent.child1).outerjoin(c2, Parent.child2).filter(or_(c1.foo == ‘bar’, c2.foo = ‘bar’)) http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#using-aliases

[sqlalchemy] relationship join with same table twice

2014-12-08 Thread Kevin S
I am trying to construct a filter against a table that has two references to the same child table. But I am completely confused how to go about it. I've seen lots of examples for using aliases, but I have not been able to get any to work. So I'll just try to give my example simply, and ask what

Re: [sqlalchemy] relationship config for join on postgres store value

2014-08-31 Thread Michael Bayer
it needs to know that because without knowing which side is “foreign”, it doesn’t know if this acts like a many-to-one or a one-to-many. and in fact the “foreign” side here is probably “User.profile”, not Zipcode.zipcode, since this is a many-to-one. then you don’t need that uselist. You p

[sqlalchemy] relationship config for join on postgres store value

2014-08-31 Thread dweitzenfeld
My User table stores 'zipcode' as a key in an hstore called 'profile.' I'd like to join users with a table I just created called zipcodes. What is the best way to do this? Thanks! class User(PsqlBase): __tablename__ = "users" __table_args__ = {'autoload': True, 'autoload_with': psql.

Re: [sqlalchemy] Relationship always returns None when accessed

2014-08-13 Thread Michael Bayer
what SQL and result set do you see being emitted if you use echo='debug' with your engine (or DEBUG logging with "sqlalchemy.engine" ) ? that will show just what queries are emitted and what data is being returned. I suggest combining this with pdb.set_trace() in the appropriate section so t

[sqlalchemy] Relationship always returns None when accessed

2014-08-13 Thread Tucker Buchy
Hi all, So I'm trying to do something fairly standard, I'm creating a db mapped object which has a many-to-one relationship to another db mapped class. I'm basically "inheriting" and bunch of attribute values from that relationship and so I want to populate those fields by reading from the rel

Re: [sqlalchemy] relationship issues

2014-06-12 Thread tyler
Thanks, I ran a similar script without any problems. It seems there's a modification somewhere to the Base we are using that causes the conflict. On Thursday, June 12, 2014 12:26:45 PM UTC-4, Simon King wrote: > > For what it's worth, the following script works for me, but I only > have access t

Re: [sqlalchemy] relationship issues

2014-06-12 Thread Simon King
For what it's worth, the following script works for me, but I only have access to sqlite at the moment, which doesn't support multiple schemas, so I had to comment those bits out. If you uncomment those and run it against your database, does it fail? If so, the problem would seem to be something to

Re: [sqlalchemy] relationship issues

2014-06-12 Thread Simon King
In that case, could you send a stripped-down single-file test case with just those 2 classes that shows the problem? Thanks, Simon On Thu, Jun 12, 2014 at 5:13 PM, wrote: > I have tried calling relationship without foreign_keys or primaryjoin, in > which case I get an error message suggesting

Re: [sqlalchemy] relationship issues

2014-06-12 Thread tyler
Also, thanks for the quick reply. -- 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 post to this group, send email to sql

Re: [sqlalchemy] relationship issues

2014-06-12 Thread tyler
I have tried calling relationship without foreign_keys or primaryjoin, in which case I get an error message suggesting I specify foreign_keys. Base is the same class for both model classes in the case where this does not work. When each model class has a different Base class things work fine. A

Re: [sqlalchemy] relationship issues

2014-06-12 Thread Simon King
On Thu, Jun 12, 2014 at 4:39 PM, wrote: > I can't seem to construct a relationship against this ServiceInstance class > without having > the Endpoint class inherit from a new declarative_base(). I've tried several > different > methods of calling relationship() and the error messages are fairly s

[sqlalchemy] relationship issues

2014-06-12 Thread tyler
I can't seem to construct a relationship against this ServiceInstance class without having the Endpoint class inherit from a new declarative_base(). I've tried several different methods of calling relationship() and the error messages are fairly similar. Below I've shown the two classes as wel

Re: [sqlalchemy] Relationship setup

2014-05-11 Thread Michael Bayer
On May 11, 2014, at 4:28 PM, Joseph Casale wrote: > Hey Michael, > > I really appreciate all that, it was extremely informative. For the academic > sake I have this > extrapolated to include all the actual intermediate tables that TableB would > include. > > For the academic sake, without th

Re: [sqlalchemy] Relationship setup

2014-05-11 Thread Joseph Casale
Hey Michael, I really appreciate all that, it was extremely informative. For the academic sake I have this extrapolated to include all the actual intermediate tables that TableB would include. For the academic sake, without the mixin and proxy, given a traditional approach where TableA is alre

Re: [sqlalchemy] Relationship setup

2014-05-11 Thread Michael Bayer
On May 11, 2014, at 12:27 AM, Joseph Casale wrote: > > > What I wanted to know was if it was possible to construct either a table > definition > for TableB so that someone could simply pass in actual values of table_a.name > to meta columns in table_b. For example if #3 above is not possible

  1   2   >