Thanks. I don't have control over the instance creation. These pre-
created objects are handed down to me. I could create an adapter that
maps the original class to the one that has been mapped but this is
quite a bit of work as I have to manually copy over each of the source
class attributes to my mapped class. I could be clever and perhaps
look for common attribute names via the internal dictionary but this
too seems clunky.

I would think this is a common problem (augmenting a class to dump
it's contents to a db but keep the original class untouched (sort of
like shelve - but w/o the
restore capability)). Is there a better way to handle this?

Thanks,

Raj

On Mar 11, 2:48 pm, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
> batraone wrote:
> >     def map(self, myfoo):
> >         'Creates the map. '
>
> >         orm.mapper(Foo, self.t_foo, column_prefix = '_')
>
> >         # Add foo to the database
> >         print dir(myfoo) # where did _name go?, _phone is there!
>
> >         mf2 = Foo() # ok, let's create a new one.
> >         print dir(mf2) # same problem
>
> > if __name__ == '__main__':
> >     f = Foo()
> >     fs = FooStore()
> >     fs.map(f)
>
> The column_prefix wasn't being honored when the mapper checked for
> existing names, this is fixed in trunk r5839.
>
> But also, don't create instances of the object before the class is mapped.
>  In particular, it's bad form to create tables and mappers inside of class
> methods.  Create class-level constructs like tables and mappers at the
> module level, in the same scope in which you create your classes.
>
>
>
> >         mf2 = Foo.Foo() # ok, let's create a new one.
> >         # AttributeError: 'Foo' object has no attribute
> > '_sa_instance_state'
> >         myfoo._phone = '555-1212' #
>
> > if __name__ == '__main__':
> >     orm.clear_mappers()
> >     f = Foo.Foo()
> >     fs = FooStore()
> >     fs.map(f)
>
> don't create instances of the object before the class is mapped.- Hide quoted 
> text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to