ash
ash copied to clipboard
Improve many_to_many default options
Is your feature request related to a problem? Please describe.
Many to many relationships are a little verbose. Also, the current default for destination_field_on_join_table would use the relationship name (tags_id), instead of the resource name (tag_id)
Describe the solution you'd like The source and destination join table fields in many to many relationships can be derived with the following defaults:
source_field_on_join_table: this_resource_id destination_field_on_join_table: destination_resource_id
Describe alternatives you've considered
Stick with the current (but fix the default for destination_field_on_join_table)
Express the feature either with a change to resource syntax, or with a change to the resource interface
This would result in a nice declaration for many_to_many relationships:
defmodule MyApp.Blog.Post do
relationships do
many_to_many :tags, MyApp.Blog.Tag do
through MyApp.Blog.PostTag
end
end
end
Looking at the code, I actually don't see any place that sets the default. So there is, in fact, no default value for destination_field_on_join_table and source_field_on_join_table. If anyone wants to tackle this, it should be a relatively straightforward addition of a transformer module similar to this one: https://github.com/ash-project/ash/blob/master/lib/ash/resource/transformers/has_destination_field.ex
Cool, I'll have a look at this
We set these defaults now.
Actually...we don't :)