3 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Sqlalchemy with ORM ...
FromSent OnAttachments
Riddler29 Mar 2007 11:35 
SteveTether29 Mar 2007 11:43 
Michael Bayer29 Mar 2007 11:45 
Subject:[sqlalchemy] Re: Sqlalchemy with ORM difficulties
From:Michael Bayer (mike@zzzcomputing.com)
Date:03/29/2007 11:45:13 AM
List:com.googlegroups.sqlalchemy

save() should not be a @classmethod.

also consider using the assignmapper extension which I think accomplishes what youre looking for.

On Mar 29, 2007, at 2:35 PM, Riddler wrote:

Guys,

I am having some difficulties in the following code. I skipped a few lines but basically I think the logic is very clear. In the line "u.save()" it produce the error which is pasted in part 2. I found that the "self" object under "save" method is different than the original one that i created by "u = BRUser()". May I ask if anyone here will have any suggestion?

Thank you. Riddler

Part 1

------------------------------------------- from sqlalchemy import * from sqlalchemy.orm import *

dbengine = create_engine('postgres://riddler:riddler@localhost:5432/ riddler') metadata = MetaData() metadata.create_all(dbengine)

class BRUser(object): isRecordExist = False

@classmethod def save(self): session = create_session() session.save(self) DBObj.session.flush() self.isRecordExist = True

BRUser_table = Table('bruser', metadata, Column('user_id', Integer, primary_key=True), Column('username', String(50)) )

mapper(BRUser, BRUser_table, properties = { 'userID': BRUser_table.c.user_id, 'username': BRUser_table.c.username })

u = BRUser() u.username = "riddler" u.save()

------------------------------------------ Part 2

------------------------------------------- sqlalchemy.exceptions.InvalidRequestError: Class 'type' entity name 'None' has no mapper associated with it