I had to include 'includes/associations.inc' before calling this function. But then it ran beautifully.