The directory reorganization is a good sign that Elixir/Phoenix are not simply rehashing Ruby/Rails for the sake of popularity but are willing to prioritize what makes the most sense for this particular language - and asking how they can improve upon what already exists.
I recently ported my app from 1.2->1.3 and moving away from Models to Contexts/Data was a simple transition that makes a lot of sense.
The `data` files (aka your new models) are basically where the schema for your model lives and the `context` (your models API) is the interface for your data.
For example when building a blog:
Instead of having User, Session, Post, and Comment models which contains your DB schema, business logic, and interfaces for getting/setting data all models directory ala Rails:
And in your data file `lib/blog_app/blog/post.ex` for example, you'd keep just your schema defining the fields like "title, permalink, body, etc" and code to handle validations and virtual attributes.
Then in your context file `lib/blog_app/blog/blog.ex` you define the API that access your data. So from your controller instead of calling:
I recently ported my app from 1.2->1.3 and moving away from Models to Contexts/Data was a simple transition that makes a lot of sense.
The `data` files (aka your new models) are basically where the schema for your model lives and the `context` (your models API) is the interface for your data.
For example when building a blog:
Instead of having User, Session, Post, and Comment models which contains your DB schema, business logic, and interfaces for getting/setting data all models directory ala Rails:
you instead create a namespace for each group of data: And in your data file `lib/blog_app/blog/post.ex` for example, you'd keep just your schema defining the fields like "title, permalink, body, etc" and code to handle validations and virtual attributes.Then in your context file `lib/blog_app/blog/blog.ex` you define the API that access your data. So from your controller instead of calling:
You now call: It makes for a very logical structure for your MVC code.