On May 7, 2007, at 2:31 PM, Cory Johns wrote:
> > I'm creating a general routine that is intended to take an > arbitrary dict of > attribute / value pairs and an ORM object instance, and use the > dict to > update the properties of the ORM instance, without knowing a priori > whether > the attributes might be relations to other tables. The problem I > ran in to > is when a property that is a relation needs to be created anew, > because then > I don't know what class to create an instance of. From looking at the > source, I found what I was looking for under the argument attribute > of the > PropertyLoader class, so I am currently doing along the lines of: > > attr_class = object_mapper(ormvar).properties[attr].argument > new_instance = attr_class() > setattr(ormvar, attr, new_instance) > > However, this feels like it might be a bit fragile, as the argument > attribute isn't explicitly document that I could find. Is there an > API / > documented way of determining the class that represents a particular > attribute, as determined by mapper() or relation()? a better choice would be property.mapper.class_ , i.e. object_mapper(ormvar).properties[attr].mapper.class_ but not every entry inside of 'properties' is a PropertyLoader, theres also column- and synonym- based properties (and someday may be others). i would think that a dict-based method of updating object attributes would itself be "shaped" the same way as an object graph, and you wouldnt have to know about classes/attribute types explicitly ? i.e. { 'attr1': 'somevalue', 'attr2': { 'subattr1':'somevalue' } } i.e. the fact that "attr2" points to a dict means that its an object- holding attribute, with its own attributes. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---