4 ms·
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
by ShaneWilton 10y 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/b030353d4b94ddd4216f6cb31e158ea59e76e046/lib/ecto/schema.ex#L339 https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216...
[2] https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216f6cb31e158ea59e76e046/lib/ecto/schema.ex#L1315 https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216...
[3] https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216f6cb31e158ea59e76e046/lib/ecto/schema.ex#L446 https://github.com/elixir-ecto/ecto/blob/b030353d4b94ddd4216...
- J0-nas 10y agoThank you