fixed getPastOrders to work with a many to many table