Wow, thank you. I'm going to try. Le lundi 10 août 2015 18:01:37 UTC+3, Michael Bayer a écrit : > > > > On 8/10/15 10:55 AM, [email protected] <javascript:> wrote: > > Hello, > > I use reflection with automap_base to load my database schema. > > # my code currently looks > Base = automap_base() > Base.prepare(engine, reflect=True) > > And for now, I want to configure the Base to take in account some > inheritance relationships. > > In database, inheritance are modeled by : > > -- base table > CREATE TABLE `hardware` ( > `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, > `type` VARCHAR(8) NOT NULL, -- indicates the type of children used > PRIMARY KEY (`id`)); > > > -- children tables (use same id of hardware) > CREATE TABLE `hdw_xxx` ( > `id` INT UNSIGNED NOT NULL, > ... > PRIMARY KEY (`id`)); > > > CREATE TABLE `hdw_yyy` ( > `id` INT UNSIGNED NOT NULL, > ... > PRIMARY KEY (`id`)); > > > There is some proper way to do this ? > > you need to build out the structure of classes which inherit up front. > you can still use reflection for pulling in the columns. see the example > at > http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/automap.html#using-automap-with-explicit-declarations > . > > Here's also a test from the test suite, doing the same thing: > > Base = automap_base() > > class Joined(Base): > __tablename__ = 'joined_base' > > type = Column(String) > > __mapper_args__ = { > "polymorphic_identity": "u0", > "polymorphic_on": type} > > class SubJoined(Joined): > __tablename__ = 'joined_inh' > __mapper_args__ = {"polymorphic_identity": "u1"} > > Base.prepare(engine=testing.db, reflect=True) > > > > > > > > > Thanks you > -- > 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 [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
