From b07c13019cf9cc8e1cc6098b85a4c0aff4c4cea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 13 Mar 2024 14:21:25 +0100 Subject: [PATCH] Mention it is ok to use code generators --- guides/contexts.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guides/contexts.md b/guides/contexts.md index 240340f4a5..789074f599 100644 --- a/guides/contexts.md +++ b/guides/contexts.md @@ -1348,6 +1348,12 @@ Great work! ## FAQ +### When to use code generators? + +In this chapter, we have used code generators for schemas, contexts, controllers, and more. If you are happy to move forward with Phoenix defaults, feel free to rely on generators to scaffold large parts of your application. When using Phoenix generators, the main question you need to answer is: does this new functionality (with its schema, table, and fields) belong to one of the existing contexts or a new one? + +This way, Phoenix generators guide you to use contexts as namespaces, allowing you to group related functionality, instead of having several dozens of schemas laying around without any structure. And remember: if you're stuck when trying to come up with a context name when the grouped functionality in your system isn't yet clear, you can simply use the plural form of the resource you're creating. + ### How do I structure code inside contexts? You may wonder how to organize the code inside contexts. For example, should you define a module for changesets (such as ProductChangesets) and another module for queries (such as ProductQueries)?