> you'd need to establish the "primary key" from the mapper's point of
> view in terms of both userId and userName.   mapper() accepts a
> "primary_key" argument for this purpose.

That kind of surprises me sqlalchemy isn't aware of what's a primary
key and what isn't.  Looking at the docs, it states mapper accepts a
primary_key argument as a list of Column objects.  I assume that's the
objects stored in the 'c' attribute.

            mapper(Job, joinOfJobsAndUsers,
                   properties={
                                'jobId' : jobTable.c.farmJobId, # part
of the primary key of jobs table
                                'try' : jobTable.c.tryIndex, # part of
the primary key of the jobs table
                                'userId' : [jobsTable.c.userId,
usersTable.c.userId], # the 2nd is the primary key of usersTable
                                'user' : usersTable.c.userName
                                },
                   primary_key=[usersTable.c.userId, usersTable.c.userName])

Is this what you mean?  I've tried this and
primary_key=[usersTable.c.userId] and all the attributes contributing
to the primary key and still see IntegrityErrors when inserting into
the users table.

<class 'sqlalchemy.exceptions.IntegrityError'>: (IntegrityError)
column userName is not unique u'INSERT INTO users ("userName") VALUES
(?)' ['totsuka']

According to the 0.5.6 docs, which I assume is pretty close to .4,

primary_key
    A list of Column objects which define the primary key to be used
against this mapper’s selectable unit. This is normally simply the
primary key of the local_table, but can be overridden here.

Looking at this, I'm not sure why userName has to be included at 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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to