Re: [sqlalchemy] Given a classname, how can I get tablename in my DeclarativeMeta

2012-03-26 Thread Daniel Nouri
On Mon, Mar 26, 2012 at 11:29 PM, Michael Bayer wrote: > > On Mar 26, 2012, at 1:53 PM, Daniel Nouri wrote: > >> I'm trying to do a few (maybe too) clever things to make SQLA >> declarative relations less verbose for the most common cases, >> especially for when two relations to the same type exis

Re: [sqlalchemy] Given a classname, how can I get tablename in my DeclarativeMeta

2012-03-26 Thread Michael Bayer
On Mar 26, 2012, at 1:53 PM, Daniel Nouri wrote: > I'm trying to do a few (maybe too) clever things to make SQLA > declarative relations less verbose for the most common cases, > especially for when two relations to the same type exist, and > therefore a 'primaryjoin' on the relationship is norma

Re: [sqlalchemy] Multiple targetmetadata's in an alembic migration?

2012-03-26 Thread Michael Bayer
On Mar 26, 2012, at 12:46 PM, John Anderson wrote: > I have some models stored in a library that have their own declarative base > and then my apps models that use their own. > > So instead of defining a single Metadata target for the migration I need to > send a list of them for it to check o

Re: [sqlalchemy] How to cascade delete a Table object?

2012-03-26 Thread Michael Bayer
On Mar 26, 2012, at 5:14 PM, Michael Bayer wrote: > To avoid loading in the rows, another way is to do what you're doing but just > use an event, see a similar recipe here: > > http://stackoverflow.com/questions/9234082/setting-delete-orphan-on-sqlalchemy-relationship-causes-assertionerror-this

Re: [sqlalchemy] How to cascade delete a Table object?

2012-03-26 Thread Michael Bayer
When you use "secondary" with relationship, SQLAlchemy maintains the rows in this table for you automatically, that is, when you remove a SkillTag from UserProfile.learn: UserProfile.learn.remove(some_skill_tag) the row in learn_tags is deleted automatically. if you want to delete some

[sqlalchemy] How to cascade delete a Table object?

2012-03-26 Thread John Anderson
I have 2 tables that are referenced via a relationship() flag, I need to figure out how to cascade delete them or delete them when their parent is deleted. My DB Structure: learn_tags = Table('learn_tags', Entity.metadata, Column('profile_pk', Integer, ForeignKey('user_profile.pk')), Col

[sqlalchemy] Given a classname, how can I get tablename in my DeclarativeMeta

2012-03-26 Thread Daniel Nouri
I'm trying to do a few (maybe too) clever things to make SQLA declarative relations less verbose for the most common cases, especially for when two relations to the same type exist, and therefore a 'primaryjoin' on the relationship is normally required. So with kemi's DeclarativeMeta, you can write

[sqlalchemy] Re: Easy way to read/write columns from an Association Object that's hidden inside an Association Proxy?

2012-03-26 Thread Robert Rollins
Ohhh, so I've just been using association_proxy improperly. Darn interesting features! You just want to implement them, even when they're not appropriate. ;) Anyway, thanks for the namespacing idea. That's exactly the kind of functionality I wanted to achieve, and I never would have thought of d

[sqlalchemy] Multiple targetmetadata's in an alembic migration?

2012-03-26 Thread John Anderson
I have some models stored in a library that have their own declarative base and then my apps models that use their own. So instead of defining a single Metadata target for the migration I need to send a list of them for it to check on. Is this possible? As an example of what I need, here is the

Re: [sqlalchemy] How to get alembic to generate migrations in the correct order?

2012-03-26 Thread John Anderson
> > So it must be detecting that my base class doesn't have any models defined > yet? So I just have to figure out why the metadata isn't setup just yet? > Inside env.py I did an import of my models and now everything works perfectly. -- You received this message because you are subscribed to th

Re: [sqlalchemy] How to get alembic to generate migrations in the correct order?

2012-03-26 Thread John Anderson
On Monday, March 26, 2012 9:00:26 AM UTC-5, Michael Bayer wrote: > > > On Mar 26, 2012, at 9:58 AM, Michael Bayer wrote: > > > > > On Mar 25, 2012, at 7:21 PM, John Anderson wrote: > > > >> I have an existing app that I want to add some features to, so I > created the new models and then ran -

Re: [sqlalchemy] Re: Getting the mapped class from a property?

2012-03-26 Thread Michael Bayer
On Mar 26, 2012, at 11:13 AM, Torsten Irländer wrote: > Hm... this approach does not seem to work: > > AttributeError: 'ColumnProperty' object has no attribute 'mapper' > > class_mapper(PersonItem).get_property('fkInstID') gives me the > ColumnProperty which does not have any mapper: try ".par

[sqlalchemy] Re: Getting the mapped class from a property?

2012-03-26 Thread Torsten Irländer
Hm... this approach does not seem to work: AttributeError: 'ColumnProperty' object has no attribute 'mapper' class_mapper(PersonItem).get_property('fkInstID') gives me the ColumnProperty which does not have any mapper: {'key': u'fkInstID', '_strategies': {: }, 'group': None, '_is_polymorphic_dis

Re: [sqlalchemy] How to get alembic to generate migrations in the correct order?

2012-03-26 Thread Michael Bayer
On Mar 26, 2012, at 9:58 AM, Michael Bayer wrote: > > On Mar 25, 2012, at 7:21 PM, John Anderson wrote: > >> I have an existing app that I want to add some features to, so I created the >> new models and then ran --autogenerate and it created me a revision file >> where in downgrade it was cr

Re: [sqlalchemy] How to get alembic to generate migrations in the correct order?

2012-03-26 Thread Michael Bayer
On Mar 25, 2012, at 7:21 PM, John Anderson wrote: > I have an existing app that I want to add some features to, so I created the > new models and then ran --autogenerate and it created me a revision file > where in downgrade it was creating all my files and in upgrade it was > dropping the tab

Re: [sqlalchemy] names of foreign keys from unknown table/class (short question)

2012-03-26 Thread Michael Bayer
Column has a collection "foreign_keys", a collection since a column in a relational database can have any number of foreign key constraints applied to it. If this collection is non-empty, then that Column is associated with a ForeignKey and thus a ForeignKeyConstraint (note that a ForeignKey is

[sqlalchemy] Re: xml approach

2012-03-26 Thread lars van gemerden
Using some of your example, together with code i wrote to XMLify simple python classes (like pickle, but xml out.input) I have got something working that handles circular references and updates the database after XML has been changed(e.g. in a client) and parsed back. It creates a reference dict w

[sqlalchemy] Re: names of foreign keys from unknown table/class (short question)

2012-03-26 Thread lars van gemerden
I must be missing something simple: i have looked in: - orm.properties.ColumnProperty (which i iterate by name using mapper.iterate_properties); couldn't find anything about foreign keys or the originating Column - Column (iterate via class.__table__.c); can see whether it is a Foreign key, but

Re: [sqlalchemy] Re: xml approach

2012-03-26 Thread Julien Cigar
On 03/23/2012 10:37, lars van gemerden wrote: Hi Julian, Thanks, I am looking into it and it looks interesting. Have you done much testing yet? How do you (plan to; haven't looked at too much detail yet) check for circular references (like backrefs)? circular references aren't handled yet