[sqlalchemy] Re: dynamically adding a validates method

2012-04-16 Thread lars van gemerden
Thank you, i got it working now. For future reference: Before creating a sa class with something like: type(typename, (Base,), classdict) I first create the classdict in which I define columns, __tablename__, etc, and validators (relationships I add later). The validators i create(using a

[sqlalchemy] Re: dynamically adding a validates method

2012-04-16 Thread lars van gemerden
PS: the validate(value) method in typedef[name] is a normal method, throwing exception on errors and returning the value when OK. On Apr 16, 2:01 pm, lars van gemerden l...@rational-it.com wrote: Thank you, i got it working now. For future reference: Before creating a sa class with something

[sqlalchemy] OT - SQL report design

2012-04-16 Thread Werner
A little off topic, but who knows. Looking for a reporting tool for SQL db's, would be even nicer if it supports SQLAlchemy. Did quit a bit of googling but haven't really come across anything in the Python world. What am I looking for: - reports to be run from within a Python application

[sqlalchemy] Re: Sqlalchemy 0.7.6 and mappers _save_obj methods.

2012-04-16 Thread rdunklau
I followed your suggestions, and implemented it in the following way: - a SessionListener class, responsible for maintaining the alternate state of the sesssion is instantiated. The class defines a before_flush, and after_flush methods, which are registered as event listeners for their respecting

[sqlalchemy] Mixing a column declared with @declared_attr into a child class is not mapped in parent class when using STI

2012-04-16 Thread Amos
I am attempting to use STI with mixins on the derived/inheriting classes. If the mixin has a simple Column, everything works great. But when I have a ForeignKey on the Column, and therefore use the `declared_attr` decorator, I get an exception when I attempt to query the child collection. For the

[sqlalchemy] Use ORM mapped class as secondary-argument in relationship

2012-04-16 Thread Max S.
Hi, for an association table I specified a ORM mapped class that I wanted to use as secondary attribute in relationship(). But I discovered, that a Table or a callable can be used only. Because in my application I do not use any explicite Table definitions, but ORM only I need to write: foo =

Re: [sqlalchemy] Re: Sqlalchemy 0.7.6 and mappers _save_obj methods.

2012-04-16 Thread Michael Bayer
OK the one area that I'd check on is how exactly you remove items from new/deleted. The public API for that is pretty much to expunge() the object from the Session (I think expiring an object should remove from deleted also but I'd have to check).The use case of modifying those lists

Re: [sqlalchemy] Use ORM mapped class as secondary-argument in relationship

2012-04-16 Thread Michael Bayer
On Apr 16, 2012, at 4:03 AM, Max S. wrote: Hi, for an association table I specified a ORM mapped class that I wanted to use as secondary attribute in relationship(). But I discovered, that a Table or a callable can be used only. Because in my application I do not use any explicite Table

[sqlalchemy] Re: Sqlalchemy 0.7.6 and mappers _save_obj methods.

2012-04-16 Thread rdunklau
On Apr 16, 4:16 pm, Michael Bayer mike...@zzzcomputing.com wrote: OK the one area that I'd check on is how exactly you remove items from new/deleted.   The public API for that is pretty much to expunge() the object from the Session (I think expiring an object should remove from deleted also

Re: [sqlalchemy] Mixing a column declared with @declared_attr into a child class is not mapped in parent class when using STI

2012-04-16 Thread Michael Bayer
what version of SQLA is that ? I cannot reproduce. test case: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base, declared_attr, has_inherited_table Base= declarative_base() class Person(Base): id = Column(Integer,

Re: [sqlalchemy] Re: Sqlalchemy 0.7.6 and mappers _save_obj methods.

2012-04-16 Thread Michael Bayer
so I think the safer options here would be: 1. for obj in session.new, use session.expunge(obj) 2. for obj in session.deleted, use session.add(obj) so #1, the difference is that it removes from _new and also detaches the state from the session, which just means it removes the session_id. you

[sqlalchemy] associationproxy for one-to-many

2012-04-16 Thread Eric Lemoine
Hi I'd like to use an associationproxy for a simple many-to-one relationship: class Child(Base): __tablename__ = 'child' id = Column(Integer, primary_key=True) name = Column(Unicode) class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True)