Hi, I tried this, but then it selects "WHERE <table>.type IN (NULL)" :(
class NonPolymorphicClass(MyBaseClass): __mapper_args__ = { 'concrete' : True } I'll try some more things, like overriding the __new__ method on the base class, to create subclasses if they are available, and instances of the base class if not. Thank you very much anyway :) Pau. 2014-03-17 15:44 GMT+01:00 Michael Bayer <mike...@zzzcomputing.com>: > maybe make a subclass of the polymorphic base, and just put __concrete__ = > True in the mapper_args. skip the non primary part. > > > > > On Mar 17, 2014, at 8:45 AM, Pau Tallada <tall...@pic.es> wrote: > > Hi, > > Can it be done in declarative? > I've tried several ways, but I cannot find a working one :/ > Basically, I think I need to redefine some self-referential relationships, > as they link against the polymorphic class. > > > Meta = declarative_meta() > > class NonPolymorphicClass(MyBaseClass): > __mapper_args__ = { > 'non_primary' : True > } > > ==> ArgumentError: Inheritance of non-primary mapper for class ' > NonPolymorphicClass' is only allowed from a non-primary mapper > > > > > class NonPolymorphicClass(MyBaseClass): > __table__ = MyBaseClass.__table__ > __mapper_args__ = { > 'non_primary' : True > } > > ==> ArgumentError: Inheritance of non-primary mapper for class ' > NonPolymorphicClass' is only allowed from a non-primary mapper > > > > > class NonPolymorphicClass(Meta): > __mapper_args__ = { > 'non_primary' : True > } > > ==> InvalidRequestError: Class <class '__main__.NonPolymorphicClass'> > does not have a __table__ or __tablename__ specified and does not inherit > from an existing table-mapped class. > > > > > class NonPolymorphicClass(Meta): > __mapper_args__ = { > 'non_primary' : True > } > > ==> InvalidRequestError: Class <class '__main__.NonPolymorphicClass'> has > no primary mapper configured. Configure a primary mapper first before > setting up a non primary Mapper. > > > 2014-03-17 13:09 GMT+01:00 Pau Tallada <tall...@pic.es>: > >> Great! >> >> I think it works for my needs :D >> >> Thank you very much! >> >> Pau. >> >> >> 2014-03-17 12:28 GMT+01:00 Michael Bayer <mike...@zzzcomputing.com>: >> >> >>> On Mar 17, 2014, at 6:48 AM, Pau Tallada <tall...@pic.es> wrote: >>> >>> Hi everyone :) >>> >>> I have an application with some kind of dynamic model. >>> Several plugins define subclasses of a common base class and override >>> their behaviour, but they do not change any column. >>> >>> In some scenarios, not all the puglins are loaded, so not all the >>> subclasses are present/defined in the Metadata, but I still need to query >>> those instances and access their columns. >>> >>> Is there any option/feature/trick to temporarily disable polymorphism in >>> a single query (or globally for a session or engine) and load all classes >>> as instances of the base class? >>> >>> >>> >>> you can use a non primary mapper: >>> >>> m = mapper(MyBase, my_base_table, non_primary=True) >>> >>> s.query(m).all() >>> >>> >>> >>> >>> The other option is to hack some kind of on-demand polymorphism myself >>> into the __new__ method of the Base class. >>> >>> Thanks! >>> >>> Pau. >>> >>> -- >>> ---------------------------------- >>> Pau Tallada Crespí >>> Dep. d'Astrofísica i Cosmologia >>> Port d'Informació Científica (PIC) >>> Tel: +34 93 586 8233 >>> ---------------------------------- >>> >>> >>> -- >>> 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 sqlalchemy@googlegroups.com. >>> Visit this group at http://groups.google.com/group/sqlalchemy. >>> For more options, visit https://groups.google.com/d/optout. >>> >>> >>> >>> -- >>> 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 sqlalchemy@googlegroups.com. >>> Visit this group at http://groups.google.com/group/sqlalchemy. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> ---------------------------------- >> Pau Tallada Crespí >> Dep. d'Astrofísica i Cosmologia >> Port d'Informació Científica (PIC) >> Tel: +34 93 586 8233 >> ---------------------------------- >> >> > > > -- > ---------------------------------- > Pau Tallada Crespí > Dep. d'Astrofísica i Cosmologia > Port d'Informació Científica (PIC) > Tel: +34 93 586 8233 > ---------------------------------- > > > -- > 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 sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > > > -- > 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 sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- ---------------------------------- Pau Tallada Crespí Dep. d'Astrofísica i Cosmologia Port d'Informació Científica (PIC) Tel: +34 93 586 8233 ---------------------------------- -- 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 sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.