[api] move common relationship related functions into a mixin