This is just an example. Say I have Client and Data in many to many relationship. I have a json API to read the clients which defines a related route to read a client's related Data. Since the Data can be quite a lot, I want to force paginating it. I have a paginated read action defined in both Client and Data. However, when I call
http://localhost:4000/api/v1/client/{id}/data
http://localhost:4000/api/v1/client/{id}/data
the data is not paginated.
Is this a bug or am I missing something? Here's the relevant code
# In Clientrelationships do many_to_many :data, MyApp.Data do public? true through MyApp.Client2Data source_attribute_on_join_resource :client_id destination_attribute_on_join_resource :data_id endendactions do defaults [:read, :destroy, update: :*] # This action is duplicated in both Client and Data because at first I thought the json api called the one on Data read :read_force_pagination do description "Limited to 500 per page." pagination do keyset? true required? true default_limit 500 max_page_size 500 end endend# In domainbase_route "/client", MyApp.Client do index :read related :data, :read_force_pagination, primary?: trueend
# In Clientrelationships do many_to_many :data, MyApp.Data do public? true through MyApp.Client2Data source_attribute_on_join_resource :client_id destination_attribute_on_join_resource :data_id endendactions do defaults [:read, :destroy, update: :*] # This action is duplicated in both Client and Data because at first I thought the json api called the one on Data read :read_force_pagination do description "Limited to 500 per page." pagination do keyset? true required? true default_limit 500 max_page_size 500 end endend# In domainbase_route "/client", MyApp.Client do index :read related :data, :read_force_pagination, primary?: trueend
Solution
You can define a read action on the target resource
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.