Hacker News new | ask | show | jobs
by ShaneWilton 3372 days ago
This code snippet is a little bit confusing if you aren't already familiar with Elixir, because most of the syntax you're seeing is actually from Ecto's [0] DSL. Calling "use Ecto.Schema" at the top of the module brings some extra functionality into the current scope. For example, embedded_schema is a macro exported by Ecto.Schema [1].

embeds_many is another such macro [2], that allows you embed another schema, in-line, into the current schema. This is contrast to your more common has_many relationship, which references another table entirely.

Here, :string, :map, etc are atoms that are being passed to the field macro [3], to define the schema for the table.

[0] Basically a super lightweight ActiveRecord

[1] https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216...

[2] https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216...

[3] https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216...

1 comments

Thank you