On Jul 7, 2010, at 5:38 AM, Chris Withers wrote:
> Michael Bayer wrote:
>> - Declarative mixins can do everything now. You need to use
>> sqlalchemy.util.classproperty in most cases to do it.
>
> Cool, but the spelling is a little cumbersome:
>
> class MyMixin:
> @classproperty
> def type_(cls):
> return Column(String(50))
>
> It'd feel more natural to spell this:
>
> from sqlalchemy.ext.declarative import MixinColumn
>
> class MyMixin:
> type_ = MixinColumn(String(50))
>
> ...or...
>
> class MyMixin:
> type_ = Column(String(50),mixin=True)
>
> Of course, this explodes a little in terms of new constructs needed for
> relationship, deferred, etc.
>
> But, essentially, the above all just needs to be spotted by DeclarativeMeta
> and indicate "copy" instead of "do nothing", right?
>
> So, how about:
>
> from sqlalchemy.ext.declarative import mixin
>
> class RefTargetMixin(object):
> target_id = mixin(Column('target_id', ForeignKey('target.id')))
> target = mixin(relationship("Target",
> primaryjoin="Target.id==%s.target_id" % cls.__name__
> )
>
> ...and so on.
>
> If you're amenable to that, I'll work up a patch set.
>
> I feel bad that I wasn't able to help with the reported bugs given how hard I
> pushed for mixins, a combination of lack of time but more lack of deep
> knowledge of the rest of SQLAlchemy was to blame :-(
The decorator approach is a little more verbose but works in all situations and
is easy to understand. mixin=True means another weird kw argument to hunt
down in documentation, MixinColumn(String) cuts out all the custom column
implementations like those of GeoAlchemy and others I have in a usage recipe on
the wiki and doesn't accomodate mapperproperties. mixin(foo) is the most
practical of the ideas above, but someone can easily create that themselves.
--
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.