Opus wrote:
> Hello,
>
> I'm a sqlalchemy newbie and I'm trying to get a handle on how and
> where to do the mappers in my app.
>
> The app consists of a frame > split window > tree control & flat
> notebook.
>
> The idea is that when you click on a node in the tree, the record is
> opened in a new tab in the flat notebook.
>
> I decided to try and use sqlalchemy orm to handle all the db
> operations but I'm having a bit of trouble.
>
> I can get it to open up and disply the first record that I select from
> the tree but if I try to open a second (different) record I get the
> following error from sqlalchemy:
>
>   File "c:\program files\python25\lib\site-packages\sqlalchemy-0.5.2-
> py2.5.egg\sqlalchemy\orm\mapper.py", line 351, in
> _configure_class_instrumentation
>     self.class_)
> sqlalchemy.exc.ArgumentError: Class '<class 'Gui.Person.Person'>'
> already has a primary mapper defined. Use non_primary=True to create a
> non primary Mapper.  clear_mappers() will remove *all* current mappers
> from all classes.
>
>
> In my main app I connect to the db, create a session, set up the
> metadata and load all the table metadata.
>
> The main app then sets up the frame which proceeds to fill my tree.
>
> When the user clicks on a node a notebook page is created which then
> maps the class to the table, reads the record and displays it. That
> works fine until I try to create a new instance of the page with a
> different record.
>
> In brief the question is, "where in a gui app should I do the
> mapping?"
>   
I use SA with wxPython for my new release of a shareware application to 
manage wine.

I have currently all the SA stuff in "model.py" (using SA declarative), 
this file is imported in the different files where I need access to the 
data (i.e. import model as db).

In wx.App.OnInit I connect to the db and create a session and keep a 
reference, then in any model I need access to the data I do again the 
"import model as db" and use wx.GetApp() to get to my session.

In other words my mappers etc are all defined in the model.py file.

I hope this helps
Werner


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to