On Apr 25, 2010, at 10:18 PM, Michael Bayer wrote:

> 
> On Apr 25, 2010, at 7:31 PM, Michael Bayer wrote:
> 
>> 
>> 
>> 
>> 
>> On Apr 25, 2010, at 1:38 PM, Torsten Landschoff 
>> <torsten.landsch...@dynamore.de> wrote:
>> 
>>> Hi everybody.
>>> 
>>> After reading the documentation on dictionary based collections at 
>>> <http://www.sqlalchemy.org/docs/mappers.html#dictionary-based-collections>, 
>>> I am wondering if I am the only one who things that this code is intuitive:
>>> item = Item()
>>> item.notes['color'] = Note('color', 'blue')
>>> print item.notes['color']
>>> I'd rather write
>>> item.notes['color'] = Note('blue')
>>> That the key is stored  with the value should be an implementation detail I 
>>> think.
>>> I extended sqlalchemy.orm.collections.MappedCollection with a few lines to 
>>> implement this (attached).
>>> 
>>> Shouldn't something like is be included with SQLAlchemy? Or is this a bad id
>> 
>> You should be able to roll this yourself as a custom dictlike collection 
>> class . 
> 
> sorry, it seems you've done that already.  I'm surprised the existing 
> attribute_mapped_collection doesn't do this already ?

well, it doesn't.  It should, and maybe should raise an error if the two values 
don't match.  It doesn't make much sense to add another collection class to do 
what the first one should.

I'm sure you noticed that you can remove the repetition by working the other 
way, i.e.:

item.note.set(Note(key="color", value="blue", desc="This should be blue 
because"))
item.note.set(Note(key="shape", value="rectangular"))

also, never do this:

class Note(object):
    def __init__(self, **args): 
        self.__dict__.update(args)

you bypass all of SQLAlchemy's history tracking logic.  do this instead:

class Note(object):
    def __init__(self, **args): 
        for k, v in args.items():
            setattr(self, k, v)




> 
> 
> 
> 
> 
>> 
>> 
>>> Greetings, Torsten
>>> 
>>> -- 
>>> DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
>>> Torsten Landschoff
>>> 
>>> Office Dresden
>>> Tel: +49-(0)351-4519587
>>> Fax: +49-(0)351-4519561
>>> 
>>> mailto:torsten.landsch...@dynamore.de
>>> http://www.dynamore.de
>>> 
>>> Registration court: Mannheim, HRB: 109659, based in Karlsruhe,
>>> Managing director:  Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz
>>> 
>>> -- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "sqlalchemy" group.
>>> To post to this group, send email to sqlalch...@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.
>>> <dictmapping.py>
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To post to this group, send email to sqlalch...@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.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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