zimt28

zimt28

Lonestar ElixirConf 2017 - KEYNOTE: Phoenix 1.3 by Chris McCord

Most Liked

michalmuskala

michalmuskala

One thing to notice is that having multiple “Product” schemas does not mean you need to have multiple tables in database!
Thanks to explicit schema declarations in ecto, you can have all of them refer to the same table in database and pick only the fields this context is interested in - leaving the others untouched. This also has the advantage of performing more optimal queries - retrieving only the columns we care for.

Database and application logic are separate - one doesn’t need to be coupled to another.

13
Post #8
josevalim

josevalim

Creator of Elixir

There is nothing that Phoenix can do that won’t require developers to think about their domain. If you don’t break into contexts, you will end-up in the situation you have today with a large web/models directory without any idea of what your application does (schemas reflect the database structure and not your application structure), how those models relate to each other and what are the proper boundaries.

However, if you break into too many contexts, or if you have contexts violating each other boundaries, you are also going to end-up with messy code anyway.

I believe questions such as where to put an embedded schema is exactly the kind of confusion that comes from having something such as web/models in the past. A schema is nothing more than Elixir module and a struct. An embedded schema as well. So you should structure them in the same way you would structure any other Elixir code.

A context is not made of schemas. A context is made of Elixir code, data structures or even processes.

10
Post #9
chrismccord

chrismccord

Creator of Phoenix

Actually we specifically want to promote the opposite. You are misinterpreting the diagram in this case. The diagram is showing the context have independent Consumer and Product entities. So this is something we want to push folks towards and I could have covered better in the talk. For example, you’d have this dir structure:

|– lib
|–––– sales/
|––––––– consumer.ex # schema
|––––––– product.ex  # schema
|––––––– sales.ex    # context
|
|–––– support/
|––––––– consumer.ex # schema
|––––––– product.ex  # schema
|––––––– support.ex  #context

[quote=“mjadczak, post:3, topic:3908”]Extract the schemas to be “global”, so that they don’t exist in any bounded context. They have the base repo functionality needed by all contexts, and the two contexts call in and use them as needed. This seems to be a return to the Phoenix 1.2 approach, but perhaps it is warranted in these cases.
[/quote]

The opposite. You won’t have global schemas and stray Repo calls. Contexts will manage their own schemas, in different tables. When you run the generators, we namespace the schema tables under the context name, so you’d have "sales_products". Your Support.Product schema could have its own database table, or it could be an embedded schema that fetches the canonical %Sales.Product{} thru the bounded api, and then decorates it as a sales product as needed. Two separate database tables or the fetch and decorate approach will depend on your app. In either, you don’t have a global schema or breaking of the bounded api.

Where Next?

Popular in Discussions Top

mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
100phlecs
Are there any downsides, like perf issues, to putting all functional components in CoreComponents as long as you prefix it with the conte...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
kostonstyle
Hi all How can I compare haskell with elixir, included tools, webservices, ect. Thanks
New
AstonJ
It’s been a while since we’ve had a thread like this, so what better way to kick off the year with :003: What does being an Elixir user ...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement