=> a
-> m ( Either (AutoKey (Db a)) (AutoKey (Db a)) )
insertByAll_xml x = insertByAll (from_xml x)
+
+
+ -- | Try to insert the given object and get its primary key
+ -- back. Or, if there's a unique constraint violation, get the
+ -- primary key of the unique thing already present.
+ --
+ -- Note: we can switch to using fmap here as soon as Functor is a
+ -- superclass of Monad (PersistBackend is a Monad).
+ --
+ insert_xml_or_select :: (PersistBackend m)
+ => a
+ -> m (AutoKey (Db a))
+ insert_xml_or_select x = do
+ tmp <- insertByAll_xml x
+ return $ (either id id) tmp