Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the models folder in Phoenix Framework version 1.4?

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.

like image 936
Nvim Avatar asked Feb 12 '19 22:02

Nvim


People also ask

Is Phoenix framework fast?

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.

What database does Phoenix use?

Phoenix uses Ecto to provide builtin support to the following databases: PostgreSQL (via postgrex ) MySQL (via myxql ) MSSQL (via tds )

What is a context in Phoenix?

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.

Is Phoenix a good framework?

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.


2 Answers

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

like image 70
TGO Avatar answered Nov 15 '22 10:11

TGO


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

like image 38
mix0lydian Avatar answered Nov 15 '22 08:11

mix0lydian