Re: [sqlalchemy] single table inheritance and instrument_class events

2017-01-17 Thread Chris Withers
On 17/01/2017 15:08, mike bayer wrote: On 01/17/2017 06:15 AM, Chris Withers wrote: Great, thanks. I assume has_inherited_table returns False where the table is defined on the class itself? it looks like has_inherited_table is just looking for non-None __table__ attribute up the inheritance

Re: [sqlalchemy] single table inheritance and instrument_class events

2017-01-17 Thread mike bayer
On 01/17/2017 06:15 AM, Chris Withers wrote: Great, thanks. I assume has_inherited_table returns False where the table is defined on the class itself? it looks like has_inherited_table is just looking for non-None __table__ attribute up the inheritance chain. (ie: normal models, and the

Re: [sqlalchemy] single table inheritance and instrument_class events

2017-01-17 Thread Chris Withers
Great, thanks. I assume has_inherited_table returns False where the table is defined on the class itself? (ie: normal models, and the "base" model in the case of single table inheritance) Chris On 16/01/2017 17:49, mike bayer wrote: at the declarative level we have this:

Re: [sqlalchemy] single table inheritance and instrument_class events

2017-01-16 Thread mike bayer
at the declarative level we have this: http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html#sqlalchemy.ext.declarative.has_inherited_table this might be better since you're really looking for a "table" up above On 01/16/2017 12:05 PM, Chris Withers wrote: Hi All, If

[sqlalchemy] single table inheritance and instrument_class events

2017-01-16 Thread Chris Withers
Hi All, If I'm using instrument_class events to add some constraints to a table, what's the 'right' way to spot when it's a subclass is being instrumented? (where I'm guessing I shouldn't add the constraints). My current attempt is here:

[sqlalchemy] Single table inheritance and __table_args__

2013-04-09 Thread Gombas, Gabor (IT)
Hi, What is the recommended method of specifying constraints on columns added by a subclass using single-table inheritance? This does not work, I get a KeyError for col_a: class BaseClass(Base) __table__ = base __table_args__ = (Index(base_col),

[sqlalchemy] single table inheritance does not work with multiple inheritance

2013-01-14 Thread Ethan Fremen
I have a pretty simple case. A base class with three sub-classes, and then a final class that inherits from the three derived classes. When persisting, sqlalchemy only sets the properties of the parent class and the first child class. In all other respects the sub-class is behaving properly;

Re: [sqlalchemy] single table inheritance does not work with multiple inheritance

2013-01-14 Thread Michael Bayer
The inheritance mechanics don't support multiple inheritance from the POV of multiple mapped classes as the base for another mapped class. Single table inheritance would be the easiest case to work at some point, but there's lots of mechanics in place right now that assume a linear path from

Re: [sqlalchemy] single table inheritance does not work with multiple inheritance

2013-01-14 Thread Michael Bayer
and if you expand upon this approach you'll probably have column conflicts too, refer to http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/declarative.html#resolving-column-conflicts for the strategy for dealing with that. On Jan 14, 2013, at 1:17 PM, Michael Bayer wrote: The inheritance

Re: [sqlalchemy] single table inheritance does not work with multiple inheritance

2013-01-14 Thread Ethan Fremen
I am all down with the power of mixins. The reason I mapped things this way is because I do have concrete instances of string, amount, and quantity. (I'm capturing data from receipts: string can be e.g. a receipt number, amount can be e.g. a total, and quantity can be something unaffiliated

Re: [sqlalchemy] single table inheritance does not work with multiple inheritance

2013-01-14 Thread Michael Bayer
I agree this could be better. Not sure how deep we'd have to go to get multiple inheritance in single inheritance form to work, mapping to inheritance hierarchies is probably what adds most complexity to the ORM as it is. It's a very rare use case though, and also gets way harder when we

Re: [sqlalchemy] Single Table Inheritance with mult-column keys

2012-08-24 Thread Rob
Hi Michael, That does exactly what I was after (and I've learned a little bit more about sqalchemy!) Thank you very much for your help. On Thursday, 23 August 2012 19:13:27 UTC+1, Michael Bayer wrote: On Aug 23, 2012, at 10:04 AM, Rob wrote: Hi Michael, I have a similar (but subtly

Re: [sqlalchemy] Single Table Inheritance with mult-column keys

2012-08-23 Thread Rob
Hi Michael, I have a similar (but subtly different) problem to this, trying to mix single- and joined-table inheritance. Essentially my model looks as follows: Product(Base) PhysicalProduct(Product) NonPhysicalProduct(Product) The Physical/NonPhysicalProduct use single table inheritance

[sqlalchemy] Single table inheritance - column not mapped

2012-08-15 Thread Kuba Dolecki
Hi, We've used joined table inheritance up to this point, but performance issues are making us explore single table inheritance. I'm running into a problem with mapper configuration. Using SQLAlchemy 0.7.8, Flask-SQLAlchemy 0.16, and Flask 0.8. Here is the inheritance: class

Re: [sqlalchemy] Single table inheritance - column not mapped

2012-08-15 Thread Michael Bayer
On Aug 15, 2012, at 10:45 AM, Kuba Dolecki wrote: Hi, We've used joined table inheritance up to this point, but performance issues are making us explore single table inheritance. I'm running into a problem with mapper configuration. Using SQLAlchemy 0.7.8, Flask-SQLAlchemy 0.16, and

Re: [sqlalchemy] Single table inheritance - column not mapped

2012-08-15 Thread Kuba Dolecki
You responded! Woot. Thanks. Here's some additional info: 1. __tablename__ is generated automatically based on the class name. Flask-SQLAlchemy does this for us. The __tablename__ for AutocreatedGroup and TopicAutocreatedGroup model is both autocreated_group. 2. Sorry, I might have included

Re: [sqlalchemy] Single table inheritance - column not mapped

2012-08-15 Thread Michael Bayer
On Aug 15, 2012, at 11:41 AM, Kuba Dolecki wrote: You responded! Woot. Thanks. Here's some additional info: 1. __tablename__ is generated automatically based on the class name. Flask-SQLAlchemy does this for us. The __tablename__ for AutocreatedGroup and TopicAutocreatedGroup model is

Re: [sqlalchemy] Single table inheritance - column not mapped

2012-08-15 Thread Kuba Dolecki
Cool, I think the approach you outlined briefly works, and I look forward to hopefully seeing it in the next release. For now, I will just add the columns back to the AutocreatedGroup class. Again, thank you. I really appreciate your help. I'll make sure to make my emails in the future more

[sqlalchemy] single table inheritance + composite primary key problem

2012-06-16 Thread Vladimir Iliev
hi, what's wrong with the following mapping ? TYPE_DEFAULT = 1 class BaseFriend(DeclarativeBase): __tablename__ = 'friends' __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} type = Column(SmallInteger, primary_key=True) user_id

Re: [sqlalchemy] single table inheritance + composite primary key problem

2012-06-16 Thread Michael Bayer
On Jun 16, 2012, at 9:37 AM, Vladimir Iliev wrote: hi, what's wrong with the following mapping ? TYPE_DEFAULT = 1 class BaseFriend(DeclarativeBase): __tablename__ = 'friends' __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}

Re: [sqlalchemy] single table inheritance + composite primary key problem

2012-06-16 Thread Vladimir Iliev
On Saturday, June 16, 2012 4:52:14 PM UTC+3, Michael Bayer wrote: On Jun 16, 2012, at 9:37 AM, Vladimir Iliev wrote: hi, what's wrong with the following mapping ? TYPE_DEFAULT = 1 class BaseFriend(DeclarativeBase): __tablename__ = 'friends'

[sqlalchemy] Single table inheritance

2012-03-21 Thread Kent
Hoping for advice: I'm using sqlalchemy against a legacy application's database design, most of which isn't in my control. I have a situation where single table inheritance should work beautifully but there is one catch: of the 7 polymorphic sub classes, there is one which is allowed to

Re: [sqlalchemy] Single table inheritance

2012-03-21 Thread Michael Bayer
On Mar 21, 2012, at 9:49 AM, Kent wrote: Hoping for advice: I'm using sqlalchemy against a legacy application's database design, most of which isn't in my control. I have a situation where single table inheritance should work beautifully but there is one catch: of the 7 polymorphic sub

Re: [sqlalchemy] Single table inheritance

2012-03-21 Thread Kent Bower
That will work for me, thanks! P.S. make a note that the doc statement that it will be a future release should be updated. On 3/21/2012 10:04 AM, Michael Bayer wrote: also polymorphic_on can be any SQL expression in 0.7, like a CASE statement if you wanted. -- You received this message

Re: [sqlalchemy] Single table inheritance

2012-03-21 Thread Michael Bayer
On Mar 21, 2012, at 10:29 AM, Kent Bower wrote: That will work for me, thanks! P.S. make a note that the doc statement that it will be a future release should be updated. can you point me right to where it says that On 3/21/2012 10:04 AM, Michael Bayer wrote: also polymorphic_on

Re: [sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-08 Thread Michael Bayer
On Dec 7, 2011, at 11:08 PM, kris wrote: Hmm, I think I want the opposite behavior. I was the defualt mapper to Resource unless a more specific mapper has been defined. I never defined a 'C' or 'D' and I would like simple get a Resource when no better mapper is found. i.e. I get

Re: [sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-08 Thread Michael Bayer
the recipe is broken, please wait until i have time to fix it, thanks. On Dec 8, 2011, at 11:27 AM, Michael Bayer wrote: On Dec 7, 2011, at 11:08 PM, kris wrote: Hmm, I think I want the opposite behavior. I was the defualt mapper to Resource unless a more specific mapper has been

Re: [sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-08 Thread Michael Bayer
OK it works (not yet in tip though). On Dec 8, 2011, at 11:43 AM, Michael Bayer wrote: the recipe is broken, please wait until i have time to fix it, thanks. On Dec 8, 2011, at 11:27 AM, Michael Bayer wrote: On Dec 7, 2011, at 11:08 PM, kris wrote: Hmm, I think I want the opposite

Re: [sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-08 Thread kris
Does this mean I can use this in 7.3? or Do I need to download tip? Also could you show me how this would work with old style mapper(...) s instead of declarative_base? Thanks, Kris -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this

Re: [sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-08 Thread Michael Bayer
works in 0.7.3. will also work in 0.7.4 Just not the current tip at the moment. the regular mapper() setup is equivalent (see http://www.sqlalchemy.org/docs/orm/mapper_config.html#classical-mappings) : discriminator_expr = case(...) mapper(Person, ..., polymorphic_on=discriminator_expr,

Re: [sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-07 Thread Michael Bayer
On Dec 7, 2011, at 2:53 AM, kris wrote: I am using a single table scheme to store for a set of resource types. I would like to load a specific class if a mapper is defined and use the base class if no more specific version can be found. Is there a way to do this? i.e. resource =

Re: [sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-07 Thread kris
Hmm, I think I want the opposite behavior. I was the defualt mapper to Resource unless a more specific mapper has been defined. I never defined a 'C' or 'D' and I would like simple get a Resource when no better mapper is found. i.e. I get Resource class for C, D and get a Resource_A for A and

[sqlalchemy] Single Table Inheritance, multiple mappers and default (base) mapper

2011-12-06 Thread kris
I am using a single table scheme to store for a set of resource types. I would like to load a specific class if a mapper is defined and use the base class if no more specific version can be found. Is there a way to do this? i.e. resource = Table('resource',

Re: [sqlalchemy] Single table inheritance + join weirdness

2011-11-16 Thread Alex Grönholm
Yeah my bad, the original query does indeed query for (Z.id, B.name). I had just changed it to A.name to get the printout for the workaround query and forgot to change it back before pasting here. If there's something I can do to contribute (not sure I'm qualified to write those tests), do

Re: [sqlalchemy] Single table inheritance + join weirdness

2011-11-16 Thread Michael Bayer
heh :) the thing about tests is that anyone who gets a couple of days of practice writing them in our style can be very productive...but everyone has just one issue they need so that threshold isn't passed ... I have a boatload of tests to write for the 0.7.4 milestone so I'll be blocking

[sqlalchemy] Single table inheritance + join weirdness

2011-11-15 Thread Alex Grönholm
I encountered a little strangeness when joining to a class using single table inheritance. I was wondering why I got no results for one particular query. This was originally encountered with PostgreSQL but was successfully reproduced with SQLite. Is this a bug or a user error?

Re: [sqlalchemy] Single table inheritance + join weirdness

2011-11-15 Thread Michael Bayer
On Nov 15, 2011, at 8:54 PM, Alex Grönholm wrote: query = session.query(Z, A.name).outerjoin(Z.b).filter(Z.id == 1) print query # WORKAROUND: # query = session.query(Z, A.name).outerjoin(Z.b).filter(Z.id == 1) # ^- use the superclass instead I'd note that these

Re: [sqlalchemy] Single table inheritance + join weirdness

2011-11-15 Thread Michael Bayer
On Nov 15, 2011, at 11:39 PM, Michael Bayer wrote: On Nov 15, 2011, at 8:54 PM, Alex Grönholm wrote: query = session.query(Z, A.name).outerjoin(Z.b).filter(Z.id == 1) print query # WORKAROUND: # query = session.query(Z, A.name).outerjoin(Z.b).filter(Z.id == 1) #

Re: [sqlalchemy] Single Table Inheritance with mult-column keys

2011-08-23 Thread Michael Bayer
here's a pastebin of it: http://pastebin.com/z8XWsv2e On Aug 16, 2011, at 7:42 PM, Michael Bayer wrote: On Aug 16, 2011, at 5:37 PM, Mike Gilligan wrote: I have a single table that looks similar to the following: class Equipment(Base): type = Column(CHAR(1), primary_key=True)

[sqlalchemy] Single Table Inheritance with mult-column keys

2011-08-16 Thread Mike Gilligan
I have a single table that looks similar to the following: class Equipment(Base): type = Column(CHAR(1), primary_key=True) sub_type = Column(CHAR(1), primary_key=True) code = Column(CHAR(5), primary_key=True) For historical purposes, I cannot modify this table. I would like to setup

Re: [sqlalchemy] Single Table Inheritance with mult-column keys

2011-08-16 Thread Michael Bayer
On Aug 16, 2011, at 5:37 PM, Mike Gilligan wrote: I have a single table that looks similar to the following: class Equipment(Base): type = Column(CHAR(1), primary_key=True) sub_type = Column(CHAR(1), primary_key=True) code = Column(CHAR(5), primary_key=True) For

[sqlalchemy] Single Table Inheritance with same Column Name

2011-05-28 Thread Dan Getelman
Hi all, I'm running SQLAlchemy 0.7.0, against MySQL 5.1. I'm having issues with a field that I'd like shared between the classes in single table inheritance that I would like to have referred to differently in the subclasses: class Post(Base): __tablename__ = 'posts' id =

[sqlalchemy] Single table inheritance subclass relations

2010-03-11 Thread Conor
I'm having trouble with many-to-one relationships to subclasses that use single table inheritance. I have tried this in 0.5.8 and 0.6beta1. Here is my test case: import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy.ext.declarative import declarative_base Base = declarative_base()

Re: [sqlalchemy] Single table inheritance subclass relations

2010-03-11 Thread Michael Bayer
Conor wrote: I'm having trouble with many-to-one relationships to subclasses that use single table inheritance. I have tried this in 0.5.8 and 0.6beta1. that's what I get for not trying to answer every single email, a 6 month old bug which I've missed. This is very small and I've created and

[sqlalchemy] single table inheritance through declarative.

2009-07-29 Thread rajasekhar911
Hi I am facing a different problem in inheritance. I am using the single table inheritance through declarative. http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#single-table-inheritance b=Base() b.id='xxx' b.name='xxx' b.type='type1' I am manually setting the type column of my

[sqlalchemy] single table inheritance and changing object's type

2009-02-25 Thread Vladimir Iliev
how can i change the type of mapped object using single table inheritance? thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com

[sqlalchemy] single table inheritance : query a subtype and its subtypes

2009-02-13 Thread GustaV
Hello! In a configuration looking like this: class Parent: pass class Child(Parent): pass class ChildChild(Child): pass I would like to query the Childs and all classes that inherits it (here: ChildChild), but not Parent instances. session.query(Child).all() returns Child type only (

[sqlalchemy] single table inheritance mapping

2008-10-30 Thread David Gardner
I have a situation similar to http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_inheritance_single with the exception that I have about 50 different types, but only one of them I want to subclass. So I was wondering id there was some option to polymorphic_identity to give it

[sqlalchemy] single table inheritance questions

2006-11-02 Thread Randall Smith
Is there a way to inherit more than one level for single table inheritance? Take this relationship for example: Animal - Dog - German Shepard Say there are 10 animals; 5 are dogs and 2 are German Shepard. session.query(Animal).select() # Should yield 10 results.