`many_to_many` error
Happy to share any code needed just not sure what the actual error means! It was working before and I have just started work on tidying up the codebase and this is now an error that has appeared
5 Replies
Looks like this is an error with all resources that have relationships across API (registries?) after updating ash
Okay downgraded and it works again but would like to upgrade any advice how to migrate from
2.9
from 2.5
The error contains instructions on how to fix it
This was a new validation that was added to prevent other bugs from popping up (which they would have). If you have a many to many across APIs you have to consider what api the through resource is in, and possibly define the underlying
has_many
relationship yourself.So I need to make the
has_many
for companies and users on the join?Yeah so the problem is that, for the
many_to_many
you have the api
set, but the join resource is not in that api.
It’s in the source api.
So
has_many :users_companies, UserCompany
And then in your many to many join_relationship :users_companies
If it helps, this is a current cross-api many_to_many that I got working with some help here:
MyApp.Sites.Site
is the source, MyApp.Accounts.User
is the destination, MyApp.Sites.SitesUsers
is the join.
Just had to specify where everything comes from and points to to help Ash hook it all up for me 😄