contexted
contexted copied to clipboard
Allow passing Ecto query and preloads as list_... function args
Closes #44.
In CRUD function generation, it will now allow calling generated list_... functions in the following ways:
-
list_items()- lists all resources unfiltered -
list_items(query)- lists all resources filtered by the query -
list_items(query, [:category, :manufacturer])- lists all resources preloaded with the associations -
list_items([:category, :manufacturer])- lists all resources preloaded with the associations
Preloads can be given as an atom (:category) or a list of atoms ([:category, :manufacturer]) just as in Repo.preload/2.
The Ecto queryable argument must be either:
- the schema of the resource, or
- a query with
fromclause that targets the schema of the resource.
For example, list_items(Item) can be called just as well as list_items(from i in Item) - these are the most commonly occurring implementations of Ecto.Queryable that make most sense when used with a specific schema.