The title says it all. I want to remove all joins from a layer.
After examining the QGIS API documentation and playing a bit with the QgsVectorLayer class I've figured out how to do it but my doubt is whether there's a better way to do this same thing. I haven't found a single example using
QgsVectorLayer.vectorJoins nor anything related to identifying which tables are joined to a layer so I don't know if this is actually the way to go.
for layer in QgsMapLayerRegistry.instance().mapLayers().values(): if layer.name() == "Fire Halls": fh_lyr = layer joinsInfo = fh_lyr.vectorJoins() for joinInfo in joinsInfo: ok = fh_lyr.removeJoin(joinInfo.joinLayerId) if ok: progress.setInfo(u'Join removed successfully') else: msg = "Couldn't remove the layer join" raise GeoAlgorithmExecutionException(msg)