In Phoenix framework 1.2 there is a models folder, but is it in version 1.4?
In version 1.2 models directory is in app->web. After checking entire folder structure models folder does not exists.
For any company that currently uses Ruby on Rails, Phoenix Framework should be on your radar, because it adds considerable performance gains. To top that off, Phoenix makes it incredibly fast to build web applications.
Phoenix uses Ecto to provide builtin support to the following databases: PostgreSQL (via postgrex ) MySQL (via myxql ) MSSQL (via tds )
At the end of the day, contexts are just modules, as are your controllers, views, etc. In Phoenix, contexts often encapsulate data access and data validation. They often talk to a database or APIs. Overall, think of them as boundaries to decouple and isolate parts of your application.
Awesome Phoenix web framework Phoenix framework is where Elixir shines. It's built-in a very elegant manner and gives you everything you need to build robust web applications as well as advanced APIs.
If you use mix phoenix.new
you will still get the old project structure along with your models folder. However, since Phoenix 1.3.0 was released, the default project structure has changed. Using the new command mix phx.new
we can see that there is no longer a dedicated models folder.
With that release, Phoenix introduced contexts: dedicated modules that expose and group related functionality. Models will no longer go into a single models folder, rather, they will be grouped into different context modules according to their functionality.
For more info, please refer to the 1.3.0 release blog post here (the Contexts section): https://phoenixframework.org/blog/phoenix-1-3-0-released
After 1.2, Phoenix stopped using the Rails-like models
syntax and design; instead, Phoenix now separates data models into schemas
and ORM functions into contexts
when these resources are generated.
The directory structure of Phoenix also changed at version >= 1.3; now your primary application modules are all in ./lib/
, with non-web and database-related (schemas, contexts) modules in ./lib/appname/
and web-facing modules (controllers, views, etc) in ./lib/appname_web/
.
If you run mix phx.gen.context Accounts User users email:string username:string
in your project, the generator will generate the ./lib/appname/accounts/
directory, containing a file called /accounts/user.ex
that contains your user schema
& changeset
and a file called /accounts/accounts.ex
that contains your database CRUD logic related to your user schema.
Check out the changelog in TGO's answer and also check out the official Phoenix docs about Contexts for a clearer picture of Phoenix's current Context design
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With