[sqlalchemy] Re: Eager load working differently?
use backref=backref(somename, lazy=False, otherargs). On Oct 23, 2006, at 8:19 AM, Maciej Szumocki wrote: After some more testing (the use of loggers in sqlalchemy helped alot :)) i have narrowed the issue to backreference creation - they seem to be always created lazy, even if relation is set to eager. Here's a simple test script (not in unittest format unfortunately as i'm not sure how to make one that would work within sqlalchemy unittest framework). from sqlalchemy import * dburi = put your own here import logging #logging.getLogger(sqlalchemy.orm.mapper.Mapper).setLevel(1) #logging.getLogger(sqlalchemy.orm.strategies.EagerLoader).setLevel (1) #uncomment if you want to see what exactly is going on engine = create_engine(dburi, strategy='plain', echo=True) metadata = BoundMetaData(engine) middle = Table('middle', metadata, Column('id', Integer, primary_key = True, autoincrement=True), Column('data', String(50)), ) left = Table('left', metadata, Column('id', Integer, ForeignKey(middle.c.id), primary_key=True), Column('tag', String(50), primary_key=True), ) right = Table('right', metadata, Column('id', Integer, ForeignKey(middle.c.id), primary_key=True), Column('tag', String(50), primary_key=True), ) class Middle(object): def __init__(self, data): self.data = data class Left(object): def __init__(self, data): self.tag = data class Right(object): def __init__(self, data): self.tag = data mapper(Left, left) mapper(Right, right) mapper(Middle, middle, properties = { 'left': relation(Left, private=True, lazy=False, backref='middle', foreignkey=left.c.id, primaryjoin = left.c.id==middle.c.id ), 'right': relation(Right, private=True, lazy=False, backref='middle', foreignkey=right.c.id, primaryjoin = right.c.id==middle.c.id ), } ) def make_data(): session = create_session(bind_to=engine) p = Middle('test1') p.left.append(Left('tag1')) p.right.append(Right('tag2')) session.save(p) session.flush() def test(close_session): session = create_session(bind_to=engine) obj = session.query(Left).get_by(tag='tag1') if close_session: session.close() print obj.middle.right[0] if __name__==__main__: metadata.create_all() try: make_data() test(False) # will work fine test(True) # will fail finally: metadata.drop_all() --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy -~--~~~~--~~--~--~---
[sqlalchemy] Re: Problem with mapper relationship when lazy=False
youre really looking to have an association object pattern here. I thought you might recommend that. My problem last time I tried an association object was that in the following situation: item table keyword table itemkeyword table (and association object) I couldn't get the keywords to eager load when I retrieve items, which is the reason I am trying to kluge this together without an association object. I'll go back and see if I can retrieve items and then do keywords = [ik.keyword for ik in item.itemkeywords] without SQLAlchemy querying the database each time separately from the query that brings back the items. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy -~--~~~~--~~--~--~---
[sqlalchemy] Re: echo and logging Turbogears and SQLAlchemy
On 10/23/06, Karl Guertin [EMAIL PROTECTED] wrote: On 10/22/06, Jorge Vargas [EMAIL PROTECTED] wrote: is this statement correct? # set to 1 to make SQLAlchemy echo SQL commands on the console sqlalchemy.echo = 0 I haven't looked at the code, but from experience I know that setting sqlalchemy.echo to anything but False in the config results in the sql statements getting echo'd. 0 would work too, of course, since it's a false value in Boolean contexts. The code never checks for if echo == False, but always a simple if echo: test, so 0, or an empty list, or any other false value will work. It's still better to use False than 0, though, because that makes it plain that it's a boolean value. -- Robin Munn [EMAIL PROTECTED] GPG key 0xD6497014 --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy -~--~~~~--~~--~--~---
[sqlalchemy] Re: Problem with mapper relationship when lazy=False
the eager load should be able to go through the association object down to the endpoint Keyword objects Thanks -- that does work. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy -~--~~~~--~~--~--~---
[sqlalchemy] Re: SQLAlchemy 0.3.0 Released
im playing around with the docs to put the one page idea back there, and im noticing the page is so enormous my browser cant navigate the page anyway (also with the 0.2 docs)...is that what you really want ? might be nicer if someone wants to work on Markdown-PDF, possibly by way of LaTeX or something like that (since the content for the docs exists in markdown format). Enrico Morelli wrote: On Mon, 23 Oct 2006 13:16:56 +0200 Marco Mariani [EMAIL PROTECTED] wrote: Jonathan Ellis wrote: Looks like another great release! Kudos to Michael and anyone involved for bringing forward the only ORM I feel like using :-) I like the docs too, but would really appreciate a PDF or PS version since the layout is not printer-friendly to me. Firefox, Konqueror and Interne Exploder do not wrap correctly the monospaced text. Openoffice crashes after filling up my RAM. No need for pagenumber and other frills.. The one-page options is also missing from 0.3. I agree with Marco. It's very important to have a printed version of the documentation. Now is very difficult to print the new documentation because one-page option missing. Thanks for your wonderful work. -- --- (o_ (o_//\ Coltivate Linux che tanto Windows si pianta da solo. (/)_ V_/_ +--+ | ENRICO MORELLI | email: [EMAIL PROTECTED] | | * * * *| phone: +39 055 4574269 | | University of Florence| fax : +39 055 4574253 | | CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY| +--+ --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy -~--~~~~--~~--~--~---