many_to_many exception after updating Ash

Previous version was 2.6.31. I updated to 2.11.8 today and an existing many_to_many association that I had is now raising an exception. Did something change? Here are my resources:
defmodule MyApp.Budgeting.Book do
relationships do
many_to_many :users, MyApp.Authentication.User do
through MyApp.Budgeting.BookUser
api MyApp.Authentication
source_attribute_on_join_resource :book_id
destination_attribute_on_join_resource :user_id
end
end
end
defmodule MyApp.Budgeting.Book do
relationships do
many_to_many :users, MyApp.Authentication.User do
through MyApp.Budgeting.BookUser
api MyApp.Authentication
source_attribute_on_join_resource :book_id
destination_attribute_on_join_resource :user_id
end
end
end
defmodule MyApp.Authentication.User do
relationships do
many_to_many :books, MyApp.Budgeting.Book do
through MyApp.Budgeting.BookUser
api MyApp.Budgeting
source_attribute_on_join_resource :user_id
destination_attribute_on_join_resource :book_id
end
end
end
defmodule MyApp.Authentication.User do
relationships do
many_to_many :books, MyApp.Budgeting.Book do
through MyApp.Budgeting.BookUser
api MyApp.Budgeting
source_attribute_on_join_resource :user_id
destination_attribute_on_join_resource :book_id
end
end
end
defmodule MyApp.Budgeting.BookUser do
relationships do
belongs_to :book, MyApp.Budgeting.Book do
allow_nil? false
end

belongs_to :user, MyApp.Authentication.User do
api MyApp.Authentication
allow_nil? false
end
end
end
defmodule MyApp.Budgeting.BookUser do
relationships do
belongs_to :book, MyApp.Budgeting.Book do
allow_nil? false
end

belongs_to :user, MyApp.Authentication.User do
api MyApp.Authentication
allow_nil? false
end
end
end
Here's the error I'm getting:
** (RuntimeError) Resource `MyApp.Budgeting.BookUser` is not accepted by api `MyApp.Authentication` for autogenerated join relationship: `:users_join_assoc`

Relationship was generated by the `many_to_many` relationship `:users`

If the `through` resource `MyApp.Budgeting.BookUser` is not accepted by the same
api as the destination resource `MyApp.Authentication.User`,
then you must define that relationship manually. To define it manually, add the following to your
relationships:

has_many :users_join_assoc, MyApp.Budgeting.BookUser do
# configure the relationship attributes
...
end

You can use a name other than `:users_join_assoc`, but if you do, make sure to
add that to `:users`, i.e

many_to_many :users_join_assoc, MyApp.Budgeting.BookUser do
...
join_relationship_name :your_new_name
end
** (RuntimeError) Resource `MyApp.Budgeting.BookUser` is not accepted by api `MyApp.Authentication` for autogenerated join relationship: `:users_join_assoc`

Relationship was generated by the `many_to_many` relationship `:users`

If the `through` resource `MyApp.Budgeting.BookUser` is not accepted by the same
api as the destination resource `MyApp.Authentication.User`,
then you must define that relationship manually. To define it manually, add the following to your
relationships:

has_many :users_join_assoc, MyApp.Budgeting.BookUser do
# configure the relationship attributes
...
end

You can use a name other than `:users_join_assoc`, but if you do, make sure to
add that to `:users`, i.e

many_to_many :users_join_assoc, MyApp.Budgeting.BookUser do
...
join_relationship_name :your_new_name
end
5 Replies
Terryble
TerrybleOP•2y ago
This is working in my app in its current state. When I tried updating all of the Ash-related libraries to the latest version, I am now getting this exception
ZachDaniel
ZachDaniel•2y ago
Yes, it only causes issues if you do specific things So we added the error to prevent surprising errors from popping up in the future for you You should follow the instructions in the error
Terryble
TerrybleOP•2y ago
Ah. Sorry, I was confused. So the join relationship now needs to be stated explicitly similar to Rails. Thanks for helping!
ZachDaniel
ZachDaniel•2y ago
Only in cases where the destination resource is in a different api 🙂
franckstifler
franckstifler•2y ago
Fell on the same issue. I went with creating another module in the different API and set migrate? false

Did you find this page helpful?