The topic of deferring object creation was brought up last December. Thanks
for sharing your solution, Peter. I wanted to see what people thought about
a different (unimplemented) approach.
When dealing with unvalidated data, a temporary object is sufficient, and
the overhead for persisting+removing the object is overkill. Typically I
just create a normal python object for this purpose. However, this approach
requires duplicating definitions of the eventual SQLObject object. (yuk!)
It would be ideal to just use the actual SQLObject itself in this situation,
but without persistence.
I realize that during the initialization of a given SQLObject, the
connection is used to create ids and such, which is why a valid connection
is required.
If there were an in-memory (non-persistent) connection type, maybe something
like the following would be possible:
in_memory_conn = SQLObject.InMemoryConnection()
db_conn = SQLObject.MySQLConnection(....)
temp = SomeSQLObject(connection=in_memory_conn)
... # do some validation actions here
if validation_passed:
persisted = SomeSQLObject(connection=db_conn)
persisted = temp
#or maybe some way to re-assign the connection of the temp object
#and have the object recreated in new connection's database??
#ie temp.save(connection=db_conn) # or resave, or copy, etc
No big deal either way... just wanted to throw the idea out there and see
what people thought. Thanks for all of the cool tools and ideas everyone...
-Charles.
|