fix database relations

@nudded just explained to me how I should use many-to-many relations in the
models. So I applied that.