Ok, so speed might become an issue for me as well; 

Do you think a similar metaclass approach would work for concrete 
inheritance would work without major drawbacks (before i do a major 
overhaul)?
Is there any indication about how much faster concrete inheritance is, 
compared to joined inheritance?

Cheers, Lars

On Friday, April 20, 2012 9:32:49 PM UTC+2, Michael Bayer wrote:
>
>
> On Apr 20, 2012, at 8:51 AM, lars van gemerden wrote:
>
> > Ok, thank you, that helps, but now i cannot inherit from Engineer, as in:
> > 
> > class BaseMixin(object):
> > 
> >     discriminator = Column(String(50))
> > 
> >     @declared_attr
> >     def __tablename__(cls):
> >         return cls.__name__
> >     @declared_attr
> >     def id(cls):
> >         return Column(Integer, primary_key = True)
> >     @declared_attr
> >     def __mapper_args__(cls):
> >         if not has_inherited_table(cls):
> >             return {'polymorphic_on': 'discriminator'}
> >         else:
> >             return {'polymorphic_identity': cls.__name__}
> > 
> > 
> > class InheritMixin(BaseMixin):
> >     @declared_attr
> >     def id(cls):
> >         super_id = super(InheritMixin, cls).id
> >         return Column(Integer, ForeignKey(super_id), primary_key = True)
> >     
> > class Person(BaseMixin, Base):
> >     name = Column(String(50))
> >    
> > class Engineer(InheritMixin, Person):
> >     job = Column(String(50))
> > 
> > class MasterEngineer(InheritMixin, Engineer):
> >     specialty = Column(String(50))
> > 
> > Gives an MRO() error and if i would reverse the baseclasses (like class 
> Engineer(Person, InheritMixin):  ... ), the inheriting classes pick up the 
> wrong id.
> > 
> > Do you see any solution for this? 
>
> yeah I suppose if you're building out joined inheritance more than one 
> level then this becomes awkward.   I never use joined inh more than one 
> level because it has too much of an impact on queries.
>
> the metaclass as you mention is always the last resort when the various 
> declarative trickery reaches its limit.   I'm not thrilled about the 
> metaclass approach because it quickly gets confusing and shouldn't be 
> necessary.   though in this case without some extra mechanism on 
> declarative, such as a __pre_declare__() method of some kind, it might be 
> the only approach.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/MH4tZazKT0EJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to