Re: [sqlalchemy] How to keep ORM Sessions in sync when using the SQL expression language as well?

2011-10-20 Thread Michael Bayer
they were flushed ! the primary key is always fetched when the ORM does an INSERT. On Oct 20, 2011, at 5:38 PM, Russell Warren wrote: > The "joe" addresses are there quite simply because you assigned them on line > 44: > > The addresses are obviously there, yes. The ids are also there, tho

Re: [sqlalchemy] How to keep ORM Sessions in sync when using the SQL expression language as well?

2011-10-20 Thread Russell Warren
> > The "joe" addresses are there quite simply because you assigned them on > line 44: > The addresses are obviously there, yes. The ids are also there, though. With no apparent select. That's the mystery to me. -- You received this message because you are subscribed to the Google Groups "sq

Re: [sqlalchemy] How to keep ORM Sessions in sync when using the SQL expression language as well?

2011-10-20 Thread Michael Bayer
On Oct 20, 2011, at 4:49 PM, Russell Warren wrote: >> I understand this somewhat and had done that, but am still confused by one >> thing: in my pure ORM case (for "joe"), how did the identity map get a hold >> of the auto-increment ids when there was no apparent emitted SQL? It seems >> ther

Re: [sqlalchemy] How to keep ORM Sessions in sync when using the SQL expression language as well?

2011-10-20 Thread Russell Warren
> > I understand this somewhat and had done that, but am still confused by one > thing: in my pure ORM case (for "joe"), how did the identity map get a hold > of the auto-increment ids when there was no apparent emitted SQL? It seems > there wasn't one done, although I suppose it could have been d

Re: [sqlalchemy] getting same sort behavior in postgres as mysql

2011-10-20 Thread Michael Bayer
On Oct 20, 2011, at 3:54 PM, Jeremy Jones wrote: > We are moving from mysql to postgres and would like to have the same > sort behavior in postgres that mysql provides. Unfortunately as the > code was written for our application, it didn't always get an explicit > "order by" because the behavior

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Michael Bayer
On Oct 20, 2011, at 11:29 AM, Alex K wrote: > Thanks! > > Very simple solve :) > > I just added: > def content_comments_level_add(mapper, context, row, target, **flags): > if mapper.class_ is Comment and 'AS level' in context.query.__str__(): > level = tuple(row)[-3] > targe

[sqlalchemy] getting same sort behavior in postgres as mysql

2011-10-20 Thread Jeremy Jones
We are moving from mysql to postgres and would like to have the same sort behavior in postgres that mysql provides. Unfortunately as the code was written for our application, it didn't always get an explicit "order by" because the behavior that was in mysql worked how it was "supposed to." Is the

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Alex K
Thanks! Very simple solve :) I just added: def content_comments_level_add(mapper, context, row, target, **flags): if mapper.class_ is Comment and 'AS level' in context.query.__str__(): level = tuple(row)[-3] target.level = level event.listen(mapper, 'populate_instance', con

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Michael Bayer
On Oct 20, 2011, at 10:45 AM, Alex K wrote: > I solve this problem with new custom Query class: it appears all you're doing is injecting an extra column into the result. Still not clear why column_property() doesn't work here. There's also the populate_instance event which would allow you

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Alex K
I solve this problem with new custom Query class: class HieSession(Session): def __init__(self, *args, **kwargs): super(HieSession, self).__init__(*args, **kwargs) self._query_cls = HieQuery class HieQuery(Query): def instances(self, cursor, __context=None): """G

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Michael Bayer
On Oct 20, 2011, at 4:03 AM, Alex K wrote: > > result2 = db.session.query(non_primary_mapper).from_statement('SELECT test.id > AS test_id, test.user_id AS test_user_id, test.reply_id AS test_reply_id, > test.text AS test_text FROM test LEFT OUTER JOIN "user" ON "user".id = > test.user_id LIMI

Re: [sqlalchemy] How to keep ORM Sessions in sync when using the SQL expression language as well?

2011-10-20 Thread Michael Bayer
On Oct 20, 2011, at 1:49 AM, Russ wrote: > > I understand this somewhat and had done that, but am still confused by one > thing: in my pure ORM case (for "joe"), how did the identity map get a hold > of the auto-increment ids when there was no apparent emitted SQL? It seems > there wasn't on

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Alex K
On Wed, Oct 19, 2011 at 7:57 PM, Michael Bayer wrote: > > > but I can't add options contains_eager like > > result = result.options(contains_eager(Comment.user)) > > Well no because you're digging way into RECURSIVE queries which SQLA > doesn't yet support very nicely. Mapping to them is not a p