[EMAIL PROTECTED] wrote: > La domanda รจ semplice: esiste un modo per non dover prestabilire se si > sta lavorando su un oggetto nuovo piuttosto che su uno esistente? Mi > andrebbe bene una cosa tipo: se la pk non esiste esegui INSERT, > altrimenti UPDATE. Se gli oggetti sono nuovi e non caricati da query > mi propone sempre e solo insert... Se la pk non esiste? Non ti capita mai di inserire una riga... conoscendo prima la chiave primaria?
Lo chiedo perche' a me succede sempre. Forse questo ti puo' essere utile http://www.sqlalchemy.org/docs/unitofwork.myt save_or_update() This method is a combination of the |save()| and |update()| methods, which will examine the given instance for a database identity (i.e. if it is transient or detached), and will call the implementation of |save()| or |update()| as appropriate. Use |save_or_update()| to add unattached instances to a session when you're not sure if they were newly created or not. Like |save()| and |update()|, |save_or_update()| cascades along the |save-update| cascade indicator, described in the |cascade| section below.
_______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python