[sqlalchemy] Re: remove an object from a property deletes from session

2009-03-27 Thread sandro dentella
On 26 Mar, 18:04, Michael Bayer mike...@zzzcomputing.com wrote: it would only do that if you have delete-orphan on the relation, and the object was never saved.it will get re-added once you attach it to that's exactly the situation I have. thanks for the explanation. sandro *:-)

[sqlalchemy] Clearing out a scoped session

2009-03-27 Thread iain duncan
Hi folks, I'm working on a set of test utilities for functional tests using SA. Because they use a turbogears model, they import the tg model and so get the SA class definitions with the mappers from the TG scoped_session. My problem is that I want to reseed this data on each test. So I have a

[sqlalchemy] Re: Getting relation orphans

2009-03-27 Thread Joril
On 26 Mar, 18:02, Michael Bayer mike...@zzzcomputing.com wrote: you can check if an object is an orphan related to a certain relation() its supposed to belong to, though there's no automated way to go from that object to the actual collection it was removed from unless you scan through all

[sqlalchemy] Re: Seperate History Tables

2009-03-27 Thread Suha Onay
The version is ok: 0.5.3 The problem is I don't know how to do the unit tests: no tests package. from tests import eq_, Comparable How can i do the unit tests? Suha On Thu, Mar 26, 2009 at 19:04, Michael Bayer mike...@zzzcomputing.com wrote: not sure.  make sure you're on 0.5.3.   do the

[sqlalchemy] session.add() or session.update() ? (NEWBIE)

2009-03-27 Thread Marcin Krol
Hello everyone, I have tested that session.add(changed_sqla_object) in at least one context (when the object with id of changed_sqla_object already exists in the db) does issue UPDATE sql query and updates the object in the database. However, there's also session.update() method. Help on

[sqlalchemy] Re: Filtering a relation

2009-03-27 Thread David Gardner
Try this: mapper(Parent, parent_table, properties = { 'boys':relation(Child, backref='parent', primaryjoin=(and_(child_table.c.pid=parent_table.c.id, child_table.c.gb=='b'), 'girls':relation(Child, backref='parent',

[sqlalchemy] Re: session.add() or session.update() ? (NEWBIE)

2009-03-27 Thread Michael Bayer
Marcin Krol wrote: Hello everyone, I have tested that session.add(changed_sqla_object) in at least one context (when the object with id of changed_sqla_object already exists in the db) does issue UPDATE sql query and updates the object in the database. However, there's also

[sqlalchemy] Re: Seperate History Tables

2009-03-27 Thread Michael Bayer
install nose and type nosetests. Suha Onay wrote: The version is ok: 0.5.3 The problem is I don't know how to do the unit tests: no tests package. from tests import eq_, Comparable How can i do the unit tests? Suha On Thu, Mar 26, 2009 at 19:04, Michael Bayer

[sqlalchemy] Re: Filtering a relation

2009-03-27 Thread Mike Conley
Thanks, it is easy and works just as expected. Using declarative it looks like this: Parent.boys = relation(Child, viewonly=True, primaryjoin=(and_(Child.pid==Parent.id, Child.bg=='b'))) Parent.girls = relation(Child, viewonly=True, primaryjoin=(and_(Child.pid==Parent.id,

[sqlalchemy] orm query - join on inner query

2009-03-27 Thread jarrod.ches...@gmail.com
How can i implement the following query with sqlalchemy.orm objects? SELECT columns.* FROM columns AS col JOIN ( SELECT object_id, revision FROM columns GROUP BY id, revision HAVING revision = 20 ) AS lr ON

[sqlalchemy] Re: orm query - join on inner query

2009-03-27 Thread Michael Bayer
subq = session.query(ColumnOrm.object_id, ColumnOrm.revision).\ group_by(ColumnOrm.id, ColumnOrm.revision).\ having(ColumnOrm.revision=20).subquery() print session.query(ColumnOrm).join((subq, and_(ColumnOrm.object_id==subq.c.object_id,