[sqlalchemy] How to close database connection of a session?

2011-04-05 Thread Gary Shi
I found session.close() doesn't close the database connection (by
calling session.close and sleep, then check the network connections),
neither session.connection().close(). How to close the connection
without quit my application?

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: How to close database connection of a session?

2011-04-05 Thread León
Hi,
I'm using session.bind.dispose()

León

On 5 abr, 07:47, Gary Shi gary...@gmail.com wrote:
 I found session.close() doesn't close the database connection (by
 calling session.close and sleep, then check the network connections),
 neither session.connection().close(). How to close the connection
 without quit my application?

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] How to close database connection of a session?

2011-04-05 Thread Gary Shi
Wow this is cool, it not only works, but also tells me some inner logic.

Because I found it's no use dispose the bind's connection pool before I
closed the session,
but it really works after the session is closed. This implies to me the
connection is still in use,
so I tried to commit or rollback the session before dispose, it also worked.

Then I found I could hold the session, and use that later. This saves me
recreate the session
and merge those objects, seems very useful to me. Thank you!

On Tue, Apr 5, 2011 at 8:12 PM, León Domingo leon.domi...@ender.es wrote:

 Hi,
 I use session.bind.dispose()

 León Domingo

 *ender*
 *LA FACTORÍA DE SOFTWARE*

 Av. Cerro del Águila 7, 2ª planta - S23
 28703 S.S. de los Reyes
 Madrid

 tlf. y fax: 902 01 44 01
 *www.ender.es*


 On 5 April 2011 07:47, Gary Shi gary...@gmail.com wrote:

 I found session.close() doesn't close the database connection (by
 calling session.close and sleep, then check the network connections),
 neither session.connection().close(). How to close the connection
 without quit my application?

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.





-- 
regards,
Gary Shi

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Two Objects, One Table and the inverse

2011-04-05 Thread Israel Ben Guilherme Fonseca
Hi,

Is it possible to break a table in two Python objects? Ex:

Python objects:

class Person:

name = Column(String)

class Address:

street = Column(String)
city = Column(String)


Table:

table Person
name varchar
city varchar
street varchar

How can i make the connection between the two? And is it possible to make
the inverse? (table Person and Address to a single Python object Person)

Thks in advance,

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] How to close database connection of a session?

2011-04-05 Thread Michael Bayer
if you don't want connections to be pooled, instead closed immediately, send 
poolclass=NullPool to create_engine().

docs:  
http://www.sqlalchemy.org/docs/core/pooling.html#switching-pool-implementations



On Apr 5, 2011, at 1:47 AM, Gary Shi wrote:

 I found session.close() doesn't close the database connection (by
 calling session.close and sleep, then check the network connections),
 neither session.connection().close(). How to close the connection
 without quit my application?
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Custom MySQL Socket with SQL Alchemy

2011-04-05 Thread Michael Bayer

On Apr 4, 2011, at 9:07 PM, Harish Tejwani wrote:

 We are trying to point SQLAlchemny (0.6.5 engine) to use custom MySQL
 Socket using URL Parameter as below
 
 
 WRITEDATASTORE = topsight_config.DATASTORE + '?unix_socket=/opt/mysql/
 mysql.sock'
 
 writeengine = create_engine(WRITEDATASTORE,
 echo=topsight_config.SQL_DEBUG, pool_recycle=3600)
 
 However this does not seem to work always. The application does work,
 however for many queries we get the following error in Log File
 
 Why is engine defaulting to /var/lib/mysql/mysql.sock? Is there
 another way to set this value while creating the Egine

That's the correct way to set the value and it works.SQLAlchemy knows 
nothing about this parameter and it is passed straight through.If it is not 
always working, that strongly suggests your application is calling a 
different create_engine() statement elsewhere which is used in some cases.   
I'd grep for it.


 
 
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/home/
 topsight/code/tsweb/data/templates/status.html.py', line 80 in
 render_body
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   ruleset =
 dict((s[0],s) for s in se.all())
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
 query.py', line 1576 in all
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
 list(self)
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
 query.py', line 1688 in __iter__
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
 self._execute_and_instances(context)
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
 query.py', line 1693 in _execute_and_instances
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]
 mapper=self._mapper_zero_or_none())
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
 session.py', line 728 in execute
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
 self._connection_for_bind(engine, close_with_result=True).execute(
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
 session.py', line 669 in _connection_for_bind
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
 self.transaction._connection_for_bind(engine)
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
 session.py', line 336 in _connection_for_bind
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   conn =
 bind.contextual_connect()
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 engine/base.py', line 1829 in contextual_connect
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]
 self.pool.connect(),
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 pool.py', line 183 in connect
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
 _ConnectionFairy(self).checkout()
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 pool.py', line 370 in __init__
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   rec =
 self._connection_record = pool.get()
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 pool.py', line 214 in get
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
 self.do_get()
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 pool.py', line 733 in do_get
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   con =
 self.create_connection()
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 pool.py', line 148 in create_connection
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
 _ConnectionRecord(self)
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 pool.py', line 254 in __init__
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]
 self.connection = self.__connect()
 [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
 lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
 pool.py', line 320 in __connect
 [Mon Apr 04 17:48:02 2011] [error] 

Re: [sqlalchemy] Two Objects, One Table and the inverse

2011-04-05 Thread Michael Bayer

On Apr 5, 2011, at 9:06 AM, Israel Ben Guilherme Fonseca wrote:

 Hi,
 
 Is it possible to break a table in two Python objects? Ex:
 
 Python objects:
 
 class Person:
 
 name = Column(String)
 
 class Address:
 
 street = Column(String)
 city = Column(String)
 
 
 Table:
 
 table Person
 name varchar
 city varchar
 street varchar
 
 How can i make the connection between the two? 

You could map Person and Address both to the table, excluding/including columns 
from each using mapper include_properties/exclude_properties (see the docs), 
however relationship() would not be able to handle the join condition of this 
table, which is table.id==table.id.

So in the practical sense, you'd just do this:

class Person(object):
@property
def address(self):
return Address(self.street, self.city)

or similarly use a composite (search the mapping documentation for composite) 
to achieve the Address class composed of that subset of columns.If you 
choose composite I'd note 0.7 improves upon the scalability of the 
composite feature significantly (for small datasets in memory it doesn't 
matter though).

 And is it possible to make the inverse? (table Person and Address to a single 
 Python object Person)

you can map to a join of the two tables as described at 
http://www.sqlalchemy.org/docs/orm/mapper_config.html#mapping-a-class-against-multiple-tables.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Two Objects, One Table and the inverse

2011-04-05 Thread Israel Ben Guilherme Fonseca
Thks for the insight Michael.

With the @property solution, its not possible to make queries like
session.query(Person).filter(Person.address.street=Something) right?
Cascade Saving/Updating in that instance should be a problem too. I tested
the composite solution, it's nice but the queries get a bit complex to do
when we want to restrict fields of the composite Object (because the need of
comparator and when we want only one field of the composite object in the
restriction not all of them). Not very straight forward.

What do you say about it?

I really think that in real-world situations i would never want to make
table become two objects, it's much more easy(implementation and
understanding) to use just one object. I'm doing a paper about ORM solutions
and that's why i'm asking about this specific feature.

I'll give a look in the inverse solution later.

Thanks again!

2011/4/5 Michael Bayer mike...@zzzcomputing.com


 On Apr 5, 2011, at 9:06 AM, Israel Ben Guilherme Fonseca wrote:

  Hi,
 
  Is it possible to break a table in two Python objects? Ex:
 
  Python objects:
 
  class Person:
 
  name = Column(String)
 
  class Address:
 
  street = Column(String)
  city = Column(String)
 
 
  Table:
 
  table Person
  name varchar
  city varchar
  street varchar
 
  How can i make the connection between the two?

 You could map Person and Address both to the table, excluding/including
 columns from each using mapper include_properties/exclude_properties (see
 the docs), however relationship() would not be able to handle the join
 condition of this table, which is table.id==table.id.

 So in the practical sense, you'd just do this:

 class Person(object):
@property
def address(self):
return Address(self.street, self.city)

 or similarly use a composite (search the mapping documentation for
 composite) to achieve the Address class composed of that subset of
 columns.If you choose composite I'd note 0.7 improves upon the
 scalability of the composite feature significantly (for small datasets in
 memory it doesn't matter though).

  And is it possible to make the inverse? (table Person and Address to a
 single Python object Person)

 you can map to a join of the two tables as described at
 http://www.sqlalchemy.org/docs/orm/mapper_config.html#mapping-a-class-against-multiple-tables
 .

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Custom MySQL Socket with SQL Alchemy

2011-04-05 Thread Harish Tejwani
That happened to be the case. On turning on SQL Debug we found this in
Apache Log.

[Mon Apr 04 18:49:26 2011] [error] 2011-04-04 18:49:26,330 INFO
sqlalchemy.engine.base.Engine.0x...b5d0 ()
[Mon Apr 04 18:49:26 2011] [error] /home/topsight/code/tsweb/tsweb/
model/__init__.py:7: SAWarning: At least one scoped session is already
present.  configure() can not affect sessions that have already been
created.
[Mon Apr 04 18:49:26 2011] [error]   Session.configure(bind=engine)

There was a Session.configure() in one of the files, we commented that
and things have been fine.

Wonder why it worked when we restarted Apache Web Server (using
mod_wsgi), and then gave errors after same page was visited few times




On Apr 5, 6:30 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Apr 4, 2011, at 9:07 PM, Harish Tejwani wrote:

  We are trying to point SQLAlchemny (0.6.5 engine) to use custom MySQL
  Socket using URL Parameter as below

  WRITEDATASTORE = topsight_config.DATASTORE + '?unix_socket=/opt/mysql/
  mysql.sock'

  writeengine = create_engine(WRITEDATASTORE,
  echo=topsight_config.SQL_DEBUG, pool_recycle=3600)

  However this does not seem to work always. The application does work,
  however for many queries we get the following error in Log File

  Why is engine defaulting to /var/lib/mysql/mysql.sock? Is there
  another way to set this value while creating the Egine

 That's the correct way to set the value and it works.    SQLAlchemy knows 
 nothing about this parameter and it is passed straight through.    If it is 
 not always working, that strongly suggests your application is calling a 
 different create_engine() statement elsewhere which is used in some cases.   
 I'd grep for it.



  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/home/
  topsight/code/tsweb/data/templates/status.html.py', line 80 in
  render_body
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   ruleset =
  dict((s[0],s) for s in se.all())
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
  query.py', line 1576 in all
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
  list(self)
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
  query.py', line 1688 in __iter__
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
  self._execute_and_instances(context)
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
  query.py', line 1693 in _execute_and_instances
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]
  mapper=self._mapper_zero_or_none())
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
  session.py', line 728 in execute
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
  self._connection_for_bind(engine, close_with_result=True).execute(
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
  session.py', line 669 in _connection_for_bind
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
  self.transaction._connection_for_bind(engine)
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/
  session.py', line 336 in _connection_for_bind
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   conn =
  bind.contextual_connect()
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
  engine/base.py', line 1829 in contextual_connect
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]
  self.pool.connect(),
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
  pool.py', line 183 in connect
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
  _ConnectionFairy(self).checkout()
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
  pool.py', line 370 in __init__
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   rec =
  self._connection_record = pool.get()
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
  pool.py', line 214 in get
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204]   return
  self.do_get()
  [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
  lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/
  pool.py', line 733 in do_get
  

Re: [sqlalchemy] Two Objects, One Table and the inverse

2011-04-05 Thread Michael Bayer

On Apr 5, 2011, at 12:30 PM, Israel Ben Guilherme Fonseca wrote:

 Thks for the insight Michael.
 
 With the @property solution, its not possible to make queries like 
 session.query(Person).filter(Person.address.street=Something) right?

that's not possible with standard SQLAlchemy expression constructs anyway.   
Normally you'd use Address.street to get clause elements against Address.
You can use hybrids to create this effect fully (see 
http://www.sqlalchemy.org/docs/07/orm/extensions/hybrid.html )


 Cascade Saving/Updating in that instance should be a problem too. I tested 
 the composite solution, it's nice but the queries get a bit complex to do 
 when we want to restrict fields of the composite Object (because the need of 
 comparator and when we want only one field of the composite object in the 
 restriction not all of them). Not very straight forward.

I'd argue the original usecase is not very straightforward either, if you have 
just one table you should map a class to it, then as far as nice accessor 
patterns, that's all Python convenience stuff you build yourself (like using 
hybrids above).   I don't see much practicality in attempting to make the 
single table act 100% like two tables do with the ORM, such as being concerned 
about casades...there are no cascades, this is one table with no foreign key 
relationships.   I see practicality in getting a pattern that works good enough 
to make coding against the model simple and straightforward.

 
 I really think that in real-world situations i would never want to make table 
 become two objects, it's much more easy(implementation and understanding) to 
 use just one object. I'm doing a paper about ORM solutions and that's why i'm 
 asking about this specific feature. 

well there's your answer... SQLAlchemy is about getting work done and not so 
much about academic exercises :).


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



RE: [sqlalchemy] Two Objects, One Table and the inverse

2011-04-05 Thread King Simon-NFHD78
 -Original Message-
 From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
 On Behalf Of Michael Bayer
 Sent: 05 April 2011 18:38
 To: sqlalchemy@googlegroups.com
 Subject: Re: [sqlalchemy] Two Objects, One Table and the inverse
 
 
 On Apr 5, 2011, at 12:30 PM, Israel Ben Guilherme Fonseca wrote:
 
 
   Thks for the insight Michael.
 
   With the @property solution, its not possible to make queries
 like session.query(Person).filter(Person.address.street=Something)
 right?
 
 
 that's not possible with standard SQLAlchemy expression constructs
 anyway.   Normally you'd use Address.street to get clause elements
 against Address.You can use hybrids to create this effect fully
 (see http://www.sqlalchemy.org/docs/07/orm/extensions/hybrid.html )
 

Out of interest, if Person and Address were standard mapped classes with
a one-to-one relationship between them, could that query be made to
work:

  session.query(Person).filter(Person.address.street==Something)

I guess it would have to be equal to:

 
session.query(Person).join(Person.address).filter(Address.street==Somet
hing)

In order for that to work, Person.address would have to be a smart
wrapper for the Address class that adds the join condition into any
attribute comparison operations.

Good idea, or silly idea? (Or perhaps it already works...)

Simon

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Two Objects, One Table and the inverse

2011-04-05 Thread Michael Bayer


On Apr 5, 2011, at 1:53 PM, King Simon-NFHD78 
simon.k...@motorolasolutions.com wrote:

 -Original Message-
 From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
 On Behalf Of Michael Bayer
 Sent: 05 April 2011 18:38
 To: sqlalchemy@googlegroups.com
 Subject: Re: [sqlalchemy] Two Objects, One Table and the inverse
 
 
 On Apr 5, 2011, at 12:30 PM, Israel Ben Guilherme Fonseca wrote:
 
 
Thks for the insight Michael.
 
With the @property solution, its not possible to make queries
 like session.query(Person).filter(Person.address.street=Something)
 right?
 
 
 that's not possible with standard SQLAlchemy expression constructs
 anyway.   Normally you'd use Address.street to get clause elements
 against Address.You can use hybrids to create this effect fully
 (see http://www.sqlalchemy.org/docs/07/orm/extensions/hybrid.html )
 
 
 Out of interest, if Person and Address were standard mapped classes with
 a one-to-one relationship between them, could that query be made to
 work:
 
  session.query(Person).filter(Person.address.street==Something)
 
 I guess it would have to be equal to:
 
 
 session.query(Person).join(Person.address).filter(Address.street==Somet
 hing)
 
 In order for that to work, Person.address would have to be a smart
 wrapper for the Address class that adds the join condition into any
 attribute comparison operations.
 
 Good idea, or silly idea? (Or perhaps it already works...)

I've stayed away from class.relationship.attribute partially because the 
namespace on .relationship isn't really wide open, also it implies a join 
occurring by itself, which would dilute the more open ended utility of 
query.join().




 
 Simon
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.