[sqlalchemy] how does a class instance find its values

2009-07-24 Thread robert rottermann
hi there, how can an instance of a class with a Table bound to it access the values of the values of its db record? what I would like to do is something like the following: class company(Base): __table__ = 'tblCompany' ... def listAssignedProducts(self): print assigned products

[sqlalchemy] Single row of a One to Many query

2009-07-24 Thread Noufal
Hello everyone, I've been using sqlalchemy with elixir for a legacy project for a while now and recently needed to write some more than trivial queries. I have the default elixir generated mappers but using only them forces me to do some data processing in my app rather than in the database.

[sqlalchemy] Re: How to do the mapper configuration when the left table and right table of Association Object are the same?

2009-07-24 Thread Stone Puzzle
That document is great, i follow it and get the right solution below: orm.mapper(User, user_table, properties={ 'friends': orm.relation(User, secondary=friend_table, primaryjoin= user_table.c.id == friend_table.c.user_id, secondaryjoin=friends_table.c.friend_id == user_table.c.id), })

[sqlalchemy] Re: Unsaved, pending instance and is an orphan problem

2009-07-24 Thread Michael Bayer
Victor Lin wrote: Hi, I am writing a turbogears2 application, with elixir. I got a problem when I try to create an new entity and attach it to another entity. I create a simple program to repruduce the problem: from elixir import * class User(Entity): name = Field(Unicode)

[sqlalchemy] Re: how does a class instance find its values

2009-07-24 Thread Michael Bayer
robert rottermann wrote: hi there, how can an instance of a class with a Table bound to it access the values of the values of its db record? what I would like to do is something like the following: class company(Base): __table__ = 'tblCompany' ... def listAssignedProducts(self):

[sqlalchemy] Re: Single row of a One to Many query

2009-07-24 Thread Mike Conley
It sounds like you need a subquery that finds last order then construct a query joining clients and orders to the subquery. http://www.sqlalchemy.org/docs/05/ormtutorial.html?highlight=subquery#using-subqueries Something like this: class Client(Base): __tablename__ = 'client' id =

[sqlalchemy] Re: Single row of a One to Many query

2009-07-24 Thread Michael Bayer
Noufal wrote: Hello everyone, I've been using sqlalchemy with elixir for a legacy project for a while now and recently needed to write some more than trivial queries. I have the default elixir generated mappers but using only them forces me to do some data processing in my app rather

[sqlalchemy] Re: Unsaved, pending instance and is an orphan problem

2009-07-24 Thread Michael Bayer
Michael Bayer wrote: Victor Lin wrote: It is a TODO within SQLAlchemy for this particular operation to not trigger an unnecessary load. I've added a patch as well as your test as http://www.sqlalchemy.org/trac/ticket/1483 to address the unnecessary load issue. It needs more testing to

[sqlalchemy] Re: Declarative, correlated subqueries

2009-07-24 Thread Gregg Lind
Mike, I totally appreciate the help, but it's just not working, for me. I feel like you've given tons of time on trying to fix this, so if anyone else wants to step in to hit me with the clue stick, that would be delightful. More details db's tried: postgres, sqlite sqlalchemy version:

[sqlalchemy] Re: Declarative, correlated subqueries

2009-07-24 Thread Michael Bayer
Gregg Lind wrote: session.query(Route.ts,Route.startpoint,Route.target,func.max(Route.hop_id).label('max_hop'))\ .group_by(Route.ts,Route.startpoint,Route.target).subquery() q = session.query(Route,sq.c.max_hop).join(sq,sq.c.max_hop==Route.hop_id) q.all() join takes tuples

[sqlalchemy] Re: Declarative, correlated subqueries

2009-07-24 Thread Gregg Lind
Thank you! That tuple thing was a fail on my part, clearly. Doing it exactly as you describe still doesn't get things to be, for lack of a better term, correlated. This, however, achieves what I want: session.query(Route,sq.c.max_hop).join((sq, and_(Route.hop_id==sq.c.max_hop,

[sqlalchemy] session.refresh() bug with adjacency lists?

2009-07-24 Thread David Gardner
I just ran across something I believe maybe a bug in session.refresh() dealing with adjacency lists. The situation is after a session.refresh() on a node (in my case a 'job'), the children and grandchildren have some of their values overridden by the refreshed node. Calling

[sqlalchemy] Re: session.refresh() bug with adjacency lists?

2009-07-24 Thread David Gardner
Forgot to mention this is SQLAlchemy 0.5.5 David Gardner wrote: I just ran across something I believe maybe a bug in session.refresh() dealing with adjacency lists. The situation is after a session.refresh() on a node (in my case a 'job'), the children and grandchildren have some of their

[sqlalchemy] Re: More SA, pyodbc, *nux and MSSQL problems

2009-07-24 Thread mtrier
On Jul 23, 8:30 am, Ed Singleton singleto...@gmail.com wrote: I've managed to get SA (0.6 branch) and pyodbc connecting to anMSSQL  db on Mac OS X, but I've recently been trying to get it working on   linux (Debian Lenny) and have been hitting some problems. It's definitely working to some