[sqlalchemy] Inheritance and mltiple references to parent table

2013-07-03 Thread Alexey Vihorev
Hi! Got this setup: class Document(Base): __tablename__ = 'document' discriminator = Column('type', String(30)) __mapper_args__ = {'polymorphic_identity':'document', 'polymorphic_on': discriminator} id = Column(Integer, primary_key=True)

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-07-03 Thread Michael Bayer
your metaclass must derive from the DeclarativeMeta class. Also, I disagree that you need this metaclass, what you're trying to do is very easy using mixins, which are supported in version 0.6: http://docs.sqlalchemy.org/en/rel_0_6/orm/extensions/declarative.html#mixing-in-columns On Jul

Re: [sqlalchemy] Inheritance and mltiple references to parent table

2013-07-03 Thread Michael Bayer
I'd discourage using metaclasses as they are more difficult to use in cases like these than mixins, which can accomplish the vast majority of use cases. I can't help with your metaclass case since there is no code here to work with, but in general a dynamic __mapper_args__, whether using a

[sqlalchemy] SQLAlchemy 0.8.2 released

2013-07-03 Thread Michael Bayer
Hey all - SQLAlchemy release 0.8.2 is now available. 0.8.2 includes several dozen bug fixes and new features, including refinement of some of the new features introduced in 0.8. Areas of improvement include Core, ORM, as well as specific fixes for dialects such as Postgresql, MySQL, Oracle,

[sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Josh Kuhn
I'm trying to get a certain access pattern to work and I need a bit of help: https://gist.github.com/deontologician/5922496 What I'm trying to do is use an association proxy to create a view of a collection that looks like a list of dictionaries (for serializing to json). I also want to update

Re: [sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Michael Bayer
On Jul 3, 2013, at 4:33 PM, Josh Kuhn deontologic...@gmail.com wrote: I'm trying to get a certain access pattern to work and I need a bit of help: https://gist.github.com/deontologician/5922496 What I'm trying to do is use an association proxy to create a view of a collection that looks

Re: [sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Michael Bayer
On Jul 3, 2013, at 5:06 PM, Michael Bayer mike...@zzzcomputing.com wrote: Do the UPDATE through Session.execute() so it's within the same transaction. .. or even just query(Gadget).with_parent(some_widget).update({machine_id: some_widget.machine_id}), then you can have those Gadget objects

Re: [sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Josh Kuhn
I've attempted the following: from sqlalchemy import Column, Integer, String, ForeignKey, create_engine from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.event import listen from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.associationproxy import

Re: [sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Michael Bayer
On Jul 3, 2013, at 5:52 PM, Josh Kuhn habi...@gmail.com wrote: I still get an integrity error because the after_flush happens after I've already tried to insert the null gadgets. If I move the flush after the widget is added to the session, but before the gadgets are, then the

Re: [sqlalchemy] Automatically setting fields on collection append

2013-07-03 Thread Josh Kuhn
On Wed, Jul 3, 2013 at 7:30 PM, Michael Bayer mike...@zzzcomputing.comwrote: @event.listens_for(Gadget, before_insert) def before_gadget(mapper, connection, target): target.machine_id = target.widget.machine_id 2. when widget is updated, gadgets need new machine_id, here UPDATE is