NoSQL adapters for Ecto: week 7 - embedded models

13 views
Skip to first unread message

Michał Muskała

unread,
Jul 14, 2015, 4:55:57 PM7/14/15
to elixi...@googlegroups.com, beam-co...@googlegroups.com
Hello everybody,

This past week I focused mainly on improving Ecto itself introducing embedded models.
Maybe I’ll explain a little bit more what that's about, as I haven't last time.
With regular database design the only way for two different records to be related is through
associations, that we all know - has_one, has_many, belongs_to - we all know it and use it daily.
But with NoSQL databases (or column types such as jsonb in PostgreSQL) we can think of a different kind of relationship, and that is embedding - storing related models, directly inside the
parent model by having a field allowing storing arbitrary objects that will host entire other model
(for embeds_one relation) or a collection of them (for embeds_many).

We decided to split the work in 4 parts:
  * introduce new syntax to Ecto.Schema (for embeds_one and embeds_many macros)
  * properly handle embedded models in changesets
  * prepare embedded models for saving and make sure we are running appropriate callbacks
  * actually save data to the database through adapters

Part one was completed during last week, as was the majority of part two. This week I intend to
focus on the remaining parts.
What's more the work that is done now for embeds, will probably be useful in the future for
supporting associations in changesets (think allows_nested_attributes_for done right).

Besides coding I've spent hours discussing all of this stuff with José and Eric, and I'm grateful to
them, that we could discuss this so thoroughly, and figure out together what would be the best
approach, as it's quite a complex issue - at one point even José experienced ENOMEM errors.

I hope this will be a great addition.

Have a great day,
Michał.
Reply all
Reply to author
Forward
0 new messages