Hi I had that same problem :-) The problem is that you declare are mapping to class that already has mapper defined for it. To work around this, I declared the class i mapped inside a function so a new class is defined every time i need to create a mapper. Where as before, When the module was loaded, The class i mapped was defined one and that was the only instance of the definition. (Probably using all the wrong python terminology)
I did something like this def create_mapper_function(self, engine, metadata_table): class OrmRecord(object): pass self._OrmRecord = OrmRecord mapper(self._OrmRecord, metadata_table) To create a new record def create_new(self): # The instance of the definition that is mapped is # self._OrmRecord # Create a new instance of the mapped class orm_record = self._OrmRecord() # populate and store orm_record.field1 = 'Yo' session.add(orm_record) This works well for me, Not sure if its the correct way to do it. On Mar 29, 3:51 pm, Opus <opusroya...@yahoo.com> 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?" > > Thanks 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 -~----------~----~----~----~------~----~------~--~---