Current section
8 Versions
Jump to
Current section
8 Versions
Compare versions
4
files changed
+20
additions
-22
deletions
| @@ -18,5 +18,5 @@ | |
| 18 18 | {<<"name">>,<<"ecto">>}, |
| 19 19 | {<<"optional">>,false}, |
| 20 20 | {<<"repository">>,<<"hexpm">>}, |
| 21 | - {<<"requirement">>,<<"~> 3.1.7">>}]]}. |
| 22 | - {<<"version">>,<<"0.1.0">>}. |
| 21 | + {<<"requirement">>,<<"~> 3.0">>}]]}. |
| 22 | + {<<"version">>,<<"0.1.1">>}. |
| @@ -44,9 +44,9 @@ defmodule TypedEctoSchema do | |
| 44 44 | - A lot of repetition. Field names appear in 3 different places, so in order to understand one |
| 45 45 | field, a reader needs to go up and down the code to get that. |
| 46 46 | - Ecto has some "hidden" fields that are added behind the scenes to the struct, such as the |
| 47 | - primary key `id`, the foreign_key `company_id`, the timestamps and the `__meta__` field for |
| 47 | + primary key `id`, the foreign key `company_id`, the timestamps and the `__meta__` field for |
| 48 48 | schemas. Knowing all those rules can be hard to remember and would probably be easily |
| 49 | - forgotten when changing the schema. Also Ecto has strange types for associations and meta that |
| 49 | + forgotten when changing the schema. Also, Ecto has strange types for associations and metadata that |
| 50 50 | need to be remembered. |
| 51 51 | |
| 52 52 | All of this makes this process extremely repetitive and error prone. Sometimes, you want to |
| @@ -100,8 +100,7 @@ defmodule TypedEctoSchema do | |
| 100 100 | ## Type Inference |
| 101 101 | |
| 102 102 | TypedEctoSchema does it's best job to guess the typespec for the field. It does so by following |
| 103 | - the elxir types as defined in [`Ecto.Schema` |
| 104 | - documentation](https://hexdocs.pm/ecto/Ecto.Schema.html#module-primitive-types). |
| 103 | + the Elixir types as defined in [`Ecto.Schema`](https://hexdocs.pm/ecto/Ecto.Schema.html#module-primitive-types). |
| 105 104 | For custom `Ecto.Type` and related schemas (embedded and associations), which are always a |
| 106 105 | module, it assumes the schemas has a type `t/0` defined, so for a schema called `MySchema`, it |
| 107 106 | will assume the type is `MySchema.t/0`, which is also, the default type generated by this |
| @@ -109,9 +108,9 @@ defmodule TypedEctoSchema do | |
| 109 108 | |
| 110 109 | ## Overriding the Typespec for a field |
| 111 110 | |
| 112 | - If for somereason you want to narrow the type or our type inference is incorrect, we allow a way |
| 113 | - to override the typespec. You do this by using the `::` operator, the same you use when defining |
| 114 | - typespecs. |
| 111 | + If for somereason you want to narrow the type or the automatic type inference is incorrect, |
| 112 | + the `::` operator allows the typespec to be overriden. |
| 113 | + This is done as you would when defining typespecs. |
| 115 114 | |
| 116 115 | So, for example, instead of |
| 117 116 | |
| @@ -141,30 +140,29 @@ defmodule TypedEctoSchema do | |
| 141 140 | ### Primary Keys |
| 142 141 | |
| 143 142 | Primary keys are generated by default and can be customized by the `@primary_key` module |
| 144 | - attribute, just as defined by Ecto. We handle `@primary_key` the same way we handle field, so you |
| 143 | + attribute, just as defined by Ecto. We handle `@primary_key` the same way we handle `field/3`, so you |
| 145 144 | can pass the same field options to it. |
| 146 145 | |
| 147 146 | However, if you want to customize the type, you need to set `@primary_key false` and define a |
| 148 | - field with a `primary_key: true`. |
| 147 | + field with `primary_key: true`. |
| 149 148 | |
| 150 149 | ### Belongs To |
| 151 150 | |
| 152 | - Belongs to generate an underlying foreign key that is dependent on a few Ecto options, as |
| 153 | - defined on [`Ecto.Schema` |
| 154 | - documentation](https://hexdocs.pm/ecto/Ecto.Schema.html#belongs_to/3-options). |
| 151 | + `belongs_to` generates an underlying foreign key that is dependent on a few Ecto options, as |
| 152 | + defined on [`Ecto.Schema`](https://hexdocs.pm/ecto/Ecto.Schema.html#belongs_to/3-options). |
| 155 153 | |
| 156 | - The options we have interest are `:foreign_key`, `:define_field` and `:type` |
| 154 | + The options we are interested in are `:foreign_key`, `:define_field` and `:type` |
| 157 155 | |
| 158 | - When you do `:null` it will add `| nil` to the generated foreign_key. |
| 156 | + When `:null` is passed, it will add `| nil` to the generated `foreign_key`'s typespec. |
| 159 157 | |
| 160 | - When you do `:enforce` it will enforce the association field instead. |
| 158 | + The `:enforce` option enforces the association field instead. |
| 161 159 | If you want to `:enforce` the foreign key to be set, you should probably pass `define_field: |
| 162 | - false` and define the foreign_key by hand by setting another `field/3`, the same way as |
| 160 | + false` and define the foreign key by hand, setting another `field/3`, the same way as |
| 163 161 | described by Ecto's doc. |
| 164 162 | |
| 165 163 | ### Timestamps |
| 166 164 | |
| 167 | - In case of the timestamps, we currently don't allow overriding the type using the `::` operator. |
| 165 | + In the case of the timestamps, we currently don't allow overriding the type by using the `::` operator. |
| 168 166 | That being said, however, we define the type of the fields using the `:type` option |
| 169 167 | ([as defined by Ecto doc](https://hexdocs.pm/ecto/Ecto.Schema.html#timestamps/1-options)) |
| 170 168 | """ |
| @@ -106,7 +106,7 @@ defmodule TypedEctoSchema.EctoTypeMapper do | |
| 106 106 | end |
| 107 107 | |
| 108 108 | ## |
| 109 | - ## Type Transformations Helpers |
| 109 | + ## Type Transformation Helpers |
| 110 110 | ## |
| 111 111 | |
| 112 112 | @spec wrap_in_list_if_many(Macro.t(), function_name()) :: Macro.t() |
| @@ -4,7 +4,7 @@ defmodule TypedEctoSchema.MixProject do | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 6 | app: :typed_ecto_schema, |
| 7 | - version: "0.1.0", |
| 7 | + version: "0.1.1", |
| 8 8 | elixir: "~> 1.7", |
| 9 9 | start_permanent: Mix.env() == :prod, |
| 10 10 | deps: deps(), |
| @@ -31,7 +31,7 @@ defmodule TypedEctoSchema.MixProject do | |
| 31 31 | {:excoveralls, "~> 0.11.1", only: :test, runtime: false}, |
| 32 32 | |
| 33 33 | # Project dependencies |
| 34 | - {:ecto, "~> 3.1.7"}, |
| 34 | + {:ecto, "~> 3.0"}, |
| 35 35 | |
| 36 36 | # Documentation dependencies |
| 37 37 | {:ex_doc, "~> 0.21", only: :dev, runtime: false} |