Refactoring ManyToMany to handle Many2Many based on several levels