Pushed deleting records to a method
Use sql query to delete orphan records