Fix a bug in resolving associations