Actually the answer is yes. merge() reconciles the current state of an instance and its associated children with existing data in the database, and returns a copy of the instance associated with the session. Usage is as follows:
merged_object = session.merge(existing_object) When given an instance, it follows these steps: - It examines the primary key of the instance. *If it’s present, it attempts to load an instance* with that primary key (or pulls from the local identity map). - *If there’s no primary key on the given instance, or the given primary key does not exist in the database, a new instance is created.* - The state of the given instance is then copied onto the located/newly created instance. - The operation is cascaded to associated child items along the merge cascade. Note that all changes present on the given instance, including changes to collections, are merged. - The new instance is returned. Generically the pattern is called: insert_or_update SQLAlchemy calls it: merge Rails calls it: find_or_create Symfony implements it as: setNew(false) and then save() MySql calls it: insert on duplicate update AJ ONeal -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.