Chris Withers wrote:
>
> class ComputedMapperArgs:
> @classproperty
> def __mapper_args__(cls):
> if cls.__name__=='Person':
> return dict(polymorphic_on=cls.discriminator)
> else:
> return dict(polymorphic_identity=cls.__name__)
>
> class Person(Base,ComputedMapperArgs):
> __tablename__ = 'people'
> id = Column(Integer, primary_key=True)
> discriminator = Column('type', String(50))
>
> class Engineer(Person,ComputedMapperArgs):
> pass
I reworked your mixin system in rae3ec57eea8c to fully traverse all of
cls.__mro__ every time and to be very explicit about rules for the current
class vs. classes that we definitely know are mixins. So the above works
as well as if you just put the ComputedMapperArgs on the base (which is
probably preferable here).
no thanks needed, feel free to divert .0001 pence of every transaction
onto our Paypal link.... :)
>
> ...blows up with:
>
> File
> "/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/ext/declarative.py",
> line 722, in __init__
> _as_declarative(cls, classname, cls.__dict__)
> File
> "/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/ext/declarative.py",
> line 679, in _as_declarative
> ignore_nonexistent_tables=True)
> File
> "/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/sql/util.py", line
> 205, in join_condition
> "between '%s' and '%s'.%s" % (a.description, b.description, hint))
> ArgumentError: Can't find any foreign key relationships between 'people'
> and 'people'.
>
> As does:
>
> class ComputedMapperArgs:
> @classproperty
> def __mapper_args__(cls):
> return dict(polymorphic_identity=cls.__name__)
>
> class Person(Base):
> __tablename__ = 'people'
> id = Column(Integer, primary_key=True)
> discriminator = Column('type', String(50))
> __mapper_args__ = dict(polymorphic_on=discriminator)
>
> class Engineer(Person,ComputedMapperArgs):
> pass
>
> ...*sigh*.
>
> I'll note that the Mixin recipe also produces this behaviour, even in
> 0.5.8.
>
> Any ideas? I really don't want to have to go through 100 or so classes
> added back in the __mapper_args__ manually...
>
> Chris
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> 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.
>
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
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.