[sqlalchemy] Re: Info needed regarding the use of cascade

2008-11-18 Thread --- [EMAIL PROTECTED] ---
Thank you Michael , you only need a single relation() + backref(), books-stock. did you mean like this ? class Stock(declarative_base): __tablename__ = 'tbl_stock' pass class Book(declarative_base): __tablename__ = 'tbl_books'

[sqlalchemy] Re: Info needed regarding the use of cascade

2008-11-18 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ---[EMAIL PROTECTED]@il06exr02.mot.com Sent: 18 November 2008 10:04 To: sqlalchemy Subject: [sqlalchemy] Re: Info needed regarding the use of cascade Thank you Michael , you

[sqlalchemy] flush session.is_modified()

2008-11-18 Thread sandro dentella
Hi, I have a code like this: if self.session.dirty: for dirty in self.session.dirty: if self.session.is_modified(dirty): return True if self.session.new: for obj in self.session.new: if self.session.is_modified(obj): return True I realized that

[sqlalchemy] Re: flush session.is_modified()

2008-11-18 Thread Michael Bayer
is_modified() shouldn't trigger a flush. is that with rc4 ? sandro dentella wrote: Hi, I have a code like this: if self.session.dirty: for dirty in self.session.dirty: if self.session.is_modified(dirty): return True if self.session.new: for obj in

[sqlalchemy] Re: flush session.is_modified()

2008-11-18 Thread Alessandro Dentella
On Tue, Nov 18, 2008 at 10:27:32AM -0500, Michael Bayer wrote: is_modified() shouldn't trigger a flush. is that with rc4 ? no it was svn rev. 4935. It's still the same with rev. 5311. I verified again: autoflush=False, just works. Autoflush=True shows that ## here session.new is not empty

[sqlalchemy] Trouble with Strings getting converted to Unicode types

2008-11-18 Thread Harish Vishwanath
Hello All, I am using Elixir 0.6.1 over SQLA 0.5rc2. Consider the below : from elixir import * class A(Entity): *... name = Field(String(40))* ... class B(A): *... address = Field(String(40))* ... engine = sqlite:///c:\\temp\\2.sqlite metadata.bind = engine setup_all(True) a =

[sqlalchemy] Re: flush session.is_modified()

2008-11-18 Thread Michael Bayer
is_modified() has a flag passive which when set to True, disables lazy loaders from executing. As it turns out the flag was also not hooked up so you'd have to use the latest trunk to get this. the reason it wants to lazily load things is because the modified calculation compares the current

[sqlalchemy] Mapper Extensions, after_update and old data

2008-11-18 Thread Adam
I have a project where I need to monitor the changes to a record - when using after_update, is it possible to see what the data was before the update? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group.

[sqlalchemy] Re: adding objects to table only once

2008-11-18 Thread Faheem Mitha
On Mon, 17 Nov 2008, Faheem Mitha wrote: Hi, I've written a session transcript to init db tables and add objects (well, rows) to the tables. The issue I'm currently facing is how to make the creating and populating the tables section of the script a no-op when the objects exist. If

[sqlalchemy] Re: flush session.is_modified()

2008-11-18 Thread Alessandro Dentella
On Tue, Nov 18, 2008 at 11:31:38AM -0500, Michael Bayer wrote: is_modified() has a flag passive which when set to True, disables lazy loaders from executing. As it turns out the flag was also not hooked up so you'd have to use the latest trunk to get this. the reason it wants to lazily

[sqlalchemy] Re: Trouble with Strings getting converted to Unicode types

2008-11-18 Thread Michael Bayer
pysqlite always returns Python unicode objects and this is outside of the realm of SQLAlchemy. I'm not familiar with a pysqlite option to change this but you should consult their site for any options related to it. Harish Vishwanath wrote: Hello All, I am using Elixir 0.6.1 over SQLA

[sqlalchemy] Re: Mapper Extensions, after_update and old data

2008-11-18 Thread Michael Bayer
the API to retrieve history for an individual attribute looks like: from sqlalchemy.orm import attributes a, u, d = attributes.get_history(Class.attribute, obj) where a, u, d are lists of added items, unchanged items, and deleted items, respectively. For a scalar attributes, a, u, d are

[sqlalchemy] Re: adding objects to table only once

2008-11-18 Thread az
my approach to this is to fetch all objects that look like my objects and then add the ones that are missing. e.g. q = query(A).filter( A.name.in_( allnames_that_should_be) ) missingnames = set( allnames_that_should_be) - set( a.name for a in q) for name in missingnames: ... probably would be

[sqlalchemy] dynamic columns

2008-11-18 Thread g00fy
hi so i have list of languages (suffixes) en de pl ru etc... now i have my article_table, when normaly i would have columns: id, title, content but now i want to have: id, title_en, title_de, title_pl, title_ru,,content_en,..,content_ru how can i create table definition dynamicly

[sqlalchemy] Re: filter on backrelation again

2008-11-18 Thread Michael Bayer
technically you'd say query(X).join(X.all_A.as_type(C)) but I don't know offhand if that use case has been implemented for join() as of yet. you can of course just say query(X).join((A, A.id==x.aid), (C, C.id==A.id)) assuming you're on joined table inheritance. all bets are off for concrete.

[sqlalchemy] filter on backrelation again

2008-11-18 Thread az
hi i have A, B, C,... inheritance, where A points to some X. how i query all Xs which are pointed by, say Cs ? if i put a backref on the reference, query(X).join( X.all_A) will give me As Bs Cs everything... or should that go down to joins? ciao svil

[sqlalchemy] Re: filter on backrelation again

2008-11-18 Thread az
query(X).join(X.all_A.of_type(C)) works but produces a subselect (select all-them-columns ...) which is huge/hard to read. i found that query(X).filter( X.all_A.of_type(C).any()) works too, and the subselect is shorter (select 1 ...). hmm, might be useful to somehow differ between a join that

[sqlalchemy] JOIN to subquery in mapper

2008-11-18 Thread indigophone
zipcode_meta_join_subquery = session.query(us_zipcode_table.c.city_id, us_zipcode_table.c.zipcode_population, us_zipcode_table.c.average_house_value).group_by(us_zipc ode_table.c.city_id).subquery() mapper(USCity, us_city_table, properties={ 'state':relation(USState,

[sqlalchemy] Vanilla parameterized query and results

2008-11-18 Thread TheShadow
All I need to be able to do is the following. (I don't need, can't use, and/or don't want ORM) query = 'SELECT col FROM table where col = :col' params = {'col':1} # and/or params = [{'col':1},{'col':2}] OR query = 'INSERT INTO table(col1,col2) VALUES(:col1,col2)' params = {'col1':1,'col2':2} #

[sqlalchemy] Re: Vanilla parameterized query and results

2008-11-18 Thread Empty
Hi, On Tue, Nov 18, 2008 at 9:39 PM, TheShadow [EMAIL PROTECTED] wrote: All I need to be able to do is the following. (I don't need, can't use, and/or don't want ORM) query = 'SELECT col FROM table where col = :col' params = {'col':1} # and/or params = [{'col':1},{'col':2}] OR query =

[sqlalchemy] Re: JOIN to subquery in mapper

2008-11-18 Thread Michael Bayer
joining to a subquery is better accomplished outside of relation() using query, such as query(USZipCode).join((subquery, subquery.c.col==USZipCode.somecol)). Now you want it as an attribute on your class. Do it like this: class USCity(object): ... @property def

[sqlalchemy] Re: Vanilla parameterized query and results

2008-11-18 Thread Michael Bayer
Providing great utility with no ORM whatsoever is one of our core values. That's why if you dont import sqlalchemy.orm, theres no ORM. A full overview of SQLAlchemy components is at: http://www.sqlalchemy.org/docs/05/intro.html On Nov 18, 2008, at 9:39 PM, TheShadow wrote: All I need

[sqlalchemy] Re: dynamic columns

2008-11-18 Thread Eric Ongerth
A way to normalize this: article_table: id title_table: article_id = primary key, also = foreign key to article_table.id language title content_table: article_id = primary key, also = foreign key to article_table.id language content mapper(Article, article_table, properties={