I think I have a similar trouble, although the symptoms are different.
I have a PostgreSQL table named 'acl' mapped as UserGroup.
Table acl
Column | Type
--------------+---------
id | integer
id_operatore | integer
cod_ruolo | text
id_asl | integer
id_azienda | integer
I overriding some columns as: (take a look specially to group_id =
cod_ruolo):
class UserGroup(DomainObject):
pass
assign_mapper(context, UserGroup, tbl['acl'],
properties = { 'user_id' : tbl['acl'].c.id_operatore,
'id_operatore': tbl['acl'].c.id_operatore,
'group_id' : tbl['acl'].c.cod_ruolo,
'cod_ruolo' : tbl['acl'].c.cod_ruolo})
I have this problem, triyng to insert data...
the first line works but the second one, doesn't inser any data into
column cod_ruolo.
1. id_operatore = item.get('id_operatore'), group_id =
item.get('cod_ruolo'))
2. id_operatore = item.get('id_operatore'), cod_ruolo =
item.get('cod_ruolo'))
Any ideas?
jo
Marco Mariani ha scritto:
Hi there
This relates to Turbogears, but is really a SA question.
I've customized TG authentication & authorization to use my autloaded
tables in Postgres and SqlAlchemy 0.3.3.
In my schema, I have User.c.uid, the login name of the users, as a
primary key
TG uses a User mapper with two distinct columns: User.c.user_id (the
primary key) and User.c.user_name (the logname).
Since I am an avid fan of meaningful primary keys (and have a legacy db
to support) I want to keep things my way, but TG does some user handling
that I have to fix.
So, to avoid patches to the TG source or useless sub-classing, I'd like
to access the same column by any of the three names.
I cannot do that with a python property on the mapper because TG should
be able to use get_by and friends.
I've come up with:
assign_mapper(context, User, tbl['users'], properties = {
'user_id': tbl['users'].c.uid, # alias for SqlAlchemyIdentity
'user_name': tbl['users'].c.uid, # alias for SqlAlchemyIdentity
'uid': tbl['users'].c.uid,
})
This seems to work (I added the third property to make 'uid' reappear!)
, but makes it impossible, for instance, to create new users:
In [1]: user = User(uid='xxx')
In [2]: session.flush()
[...]
SQLError: (IntegrityError) null value in column "uid" violates not-null
constraint
'INSERT INTO users (uid, nome, cognome, codice_fiscale) VALUES
(%(uid)s, %(name)s, %(surname)s)' {'surname': None, 'uid': None, 'name':
None}
In [3]: user = User(user_id='xxx')
In [4]: session.flush()
[...]
SQLError: (IntegrityError) null value in column "uid" violates not-null
constraint
'INSERT INTO users (uid, nome, cognome, codice_fiscale) VALUES
(%(uid)s, %(name)s, %(surname)s)' {'surname': None, 'uid': None, 'name':
None}
I reckon I should probably go ahead and patch TG, but maybe there is a
clean way to do what I have in mind?
Thank you.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---