thanks for testing that for me. added a fix + unit test in rev 2219.
On Jan 19, 2007, at 4:48 PM, jose wrote:
>
> I tried this....
>
> class UserGroup(DomainObject):
> pass
> assign_mapper(context, UserGroup, tbl['acl'],
> properties = {
> 'id_operatore': tbl
> ['acl'].c.id_operatore, 'user_id' : synonym('id_operatore',
> proxy=True),
> 'cod_ruolo' : tbl['acl'].c.cod_ruolo,
> 'group_id': synonym('cod_ruolo', proxy=True)
>
> }
> )
> but...
> File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line
> 552, in init
> File "build/bdist.linux-i686/egg/sqlalchemy/ext/assignmapper.py",
> line 23, in __init__
> File "build/bdist.linux-i686/egg/sqlalchemy/orm/properties.py",
> line 38, in __set__
> AttributeError: 'SynonymProperty' object has no attribute 'set'
>
>
> Michael Bayer wrote:
>
>>
>> in both of these cases, a particular Column can only be expressed
>> on the Mapper once. I should add some error checking to Mapper
>> to insure that this is followed. The reason is simple: if a
>> class has two attributes "a" and "b" which both point to a column
>> "C", and I set "a" to "5" and "b" to "7" and then flush(), which
>> attribute do I persist ?
>>
>> therefore, a quick way to make a synonym for these attributes is
>> to use "synonym" with proxy=True which will automatically set up
>> the attribute on the class:
>>
>> mapper(Class, table, properties={
>> 'id':table.c.id,
>> 'name':synonym('id', proxy=True)
>> })
>>
>> where both "id" and "name" utlimately point to just the "id"
>> information on the class.
>>
>>
>> On Jan 19, 2007, at 9:48 AM, Jose Soares wrote:
>>
>>>
>>> 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
-~----------~----~----~----~------~----~------~--~---