16 May 21:48
Is inserting new data with column_mapped_collection inconsistent?
From: Allen Bierbaum <abierbaum <at> gmail.com>
Subject: Is inserting new data with column_mapped_collection inconsistent?
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-16 19:51:42 GMT
Subject: Is inserting new data with column_mapped_collection inconsistent?
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-16 19:51:42 GMT
I have just started using column_mapped_collections. (http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relation_collections_dictcollections I must say, these are very powerful and extremely nice when reading data. But I have run into one thing that seems confusing when it comes to creating new objects in a session. Namely, it is possible to add data to the mapped dictionary in such a way that the data structure is inconsistent and not what it would be when reading the same data back. Using the example from the documentation as a start: mapper(Item, items_table, properties={ 'notes': relation(Note, collection_class=column_mapped_collection(notes_table.c.keyword)), }) # ... item = Item() item.notes['color'] = Note('color', 'blue') # Set keyword attribute to 'color' print item.notes['color'] Everything is good here, but what if I did it this way instead.... item.notes['not-color'] = Note('color', 'blue') This last line is the problem because it has inserted a link to a new Note that has a keyword of 'color' but is showing up in the dictionary as 'not-color'. If we(Continue reading)
RSS Feed