finished script to get related from db