Thanks for the response. It does help.
I can stop trying to fit the square peg into the round hole now. ;-)

I'll give the __getattr__ method a shot tonight.

Nicky

On Aug 27, 4:58 am, "Gaetan de Menten" <[EMAIL PROTECTED]> wrote:
> On Tue, Aug 26, 2008 at 5:15 AM, Nicky <[EMAIL PROTECTED]> wrote:
>
> > I apologize for my poorly posted previous message. Here is the whole
> > thing hopefully.
>
> > I have been going through the recipe and I do have working example.
>
> > I have created a wrapper class for the session and to house the
> > entities. I'd like to stitch the session back into the entity so that
> > the entity has  a query attribute once again. Is this possible (or
> > better yet: easy)?
>
> > from sqlalchemy.orm import scoped_session, sessionmaker
> > from sqlalchemy import create_engine
> > from model import  *
>
> > class dbFile:
> >        def __init__(self, filename , echo=False ):
> >                self.filename
> >                self.uri_db = 'sqllite:///' + filename
> >                self.engine =  create_engine(self.uri_db, echo=echo)
> >                self.session = scoped_session(
> >                        sessionmaker(autoflush=True,
> >                                        autocommit=True,
> >                                        bind=self.engine))
> >                for e in entities:
> >                        dbFile.__dict__[e.__name__] = e
>
> >        def toXML(self):
> >                print "<db filename='%s'>" % (self.filename,)
> >                for e in entities:
> >                        e.toXMLself.session)
> >                        # I want to use :
> >                        # e.toXML()  # ie. a linked in session.
> >                print "</db>"
>
> > if __name__ == '__main__':
> >    print "Here we go"
> >    # Fully pathed
> >    d1 = dbFile("/tmp/one.db")
> >    # Relatively pathed
> >    d2 = dbFile("two.db")
>
> > # This works
> >    d2.session.query(d2.Scale).all()
>
> > # I want this again:
> > #    d1.Scale.query.all()
> >     ^^^^^^^^^^^^^^^^^^^^^^^
> > Any pointers?
>
> You could easily assign e._descriptor.session but that wouldn't do
> what you expect.
> Well, what you want doesn't seem to be possible to achieve simply,
> because d1.Scale refers to a class/entity and each entity can only be
> "assigned" to one scoped session.
>
> The only solution I see is to override __getattr__ on dbFile to
> provide some "fake" classes/entities with a query attribute which'd
> work that way. Those fake objects could even be instrumented in a way
> they look like the real classes.
>
> Hope it helps,
> --
> Gaëtan de Mentenhttp://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to