Closed staylorwr closed 1 year ago
We could then use this functionality to add some nicer UI around many to many relationships. Currently many-to-many's only contain the belongs-to like resource link in the index view alongside any pivot field relationships. It would be nice to be able to add:
ManyToMany.make(:tags)
|> ManyToMany.with_index_fields([
Text.make(:title),
Boolean.make(:active),
Select.make(:featured),
])
|> ManyToMany.with_pivot_fields([
Text.make(:foo),
Boolean.make(:bar)
])
so that the text field replaces the belongs-to like resource link
Context
As an engineer, I want to configure a custom list of fields for a particular has many relationships. We consistently get client requests for the ability to change which fields end up on has many index table. eg with the following schemas:
In a case like this we might define the PostResource fields list as something like:
What if I don't want the tags & author on the index of the User's posts? What if I want to add other fields like a published at or (insert something else) that makes more sense when viewing an author's list of posts?
Feature
Add a function
with_index_fields/2
tohas_many.ex
that adds those fields to the private options of the `field struct. ie:Use this list of fields in
ExTeal.Resource.Index
when a has many resource is queried. We can userelationship_type
query param as a switch for which fields should be used.There's some trickery in getting that list of fields available when sorting, filtering, and searching that will require a little more thought.