Chris Withers wrote:
> Michael Bayer wrote:
>>> Michael Bayer wrote:
>>>> The Column objects you declare within declarative become members of
>>>> the underlying Table object, so its not as simple as just having
>>>> those members present on a mixin - what would really be needed would
>>>> be some sort of copying of each column object when declarative comes
>>>> across them.
>>> Indeed, how about a marker on "abstract" base classes like the Django
>>> ORM?
>>
>> im sorry, did you say you were feeling slightly sick earlier ? :)
>
> An abstract marker on a base class to say "actually, this is just here
> to provide information and methods, it's not table-mapped class" isn't
> such a bad thing, is it? Especially given how horrible the resulting
> code is...
>
>> I noticed you cut out the part of my reply with the likely fix here, to
>> provide a special class that is specifically for declarative mixins.  It
>> would only allow elements on it that make sense for copying to many
>> subclasses.
>
> I did indeed miss this, but I don't see how it's fundamentally different
> from marking a base class as abstract ;-)

its not.  I was still recovering from seeing the word "django" :)

> Uh oh:
>
> sqlalchemy.exc.ArgumentError: Mapper Mapper|Employee|employee could not
> assemble any primary key columns for mapped table 'employee'
>
> ...which makes me wonder if the class decorator would actually work at
> all. Surely it'll only kick in after the DeclarativeMeta has already
> done its thing and got upset?

the mapper is mostly configured by the time the class is done, and the
primary key columns are required to be there.  The overwhelming use case
we're talking about here are columns like "created_at", "updated_at",
etc., not primary keys.

But agreed, make your mixin implement a marker class from the declarative
module (MixinsDeclarative, i dunno), and as_declarative() will issue
copy() for the Column objects within.  It will raise errors for relation()
since it doesn't make sense to copy those.

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to