On Feb 7, 2008, at 1:33 PM, Richard Levasseur wrote:

> For the syntax of it, I'd go for something like
> `child_obj.change_from(parent_obj)` or `child_obj =
> ChildClass.create_from(parent_obj)`, perhaps implicitly invoked when
> you do child_obj.type = parent_obj.  Not sure about that last part,
> doesn't seem pythonic, and feels misleading.  The point is to allow
> the child the ability to perform custom operations if need be
> (__change_type__?).  Is the `session` part really necessary (I thought
> objects knew what session, if any, they were attached to?).  I don't
> recall exactly if this is possible, but perhaps the child can have its
> __dict__ set to the parent's?  That'd preserve any state and wouldn't
> require any loop-copy of attributes.

the "session" part is introduced only in that we try not to attach  
lots of methods and accessors to user-defined classes. we like to  
leave user-defined classes as unmodified as possible which at the very  
least helps with the possibility of name collisions (like, if someones  
SA app has a "change_from" method already, this change would break  
their app).   since everything else comes from "session" (like  
expunge(), refresh(), etc) this is where we like to put these things  
for consistency.

however, thinking further about this I think how we'd actually do this  
would be the same way we do a "primary key switch" - the mapper  
already knows how to detect the "delete" of one instance and the  
"insert" of another, both with the same primary key attributes, and  
turn it into an "update".  So i would see this as an extension to that  
functionality, i.e.:

parent = sess.query(Parent).get(1)
child = Child(id=1)
child.someattr = parent.someattr  # copy attributes
sess.delete(parent)
sess.save(child)
sess.flush()





--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to