Skip to content

Commit

Permalink
Document PolymorphicEmbed.get_polymorphic_module/3
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuprog committed Jun 2, 2024
1 parent 58eedd4 commit 8b9ff8a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ You may use `PolymorphicEmbed.HTML.Component.polymorphic_embed_inputs_for/1` whe
</.form>
```

### Get the type of a polymorphic embed
### Get the type and module of a polymorphic embed

Sometimes you need to serialize the polymorphic embed and, once in the front-end, need to distinguish them.
`PolymorphicEmbed.get_polymorphic_type/3` returns the type of the polymorphic embed:
Expand All @@ -255,6 +255,12 @@ Sometimes you need to serialize the polymorphic embed and, once in the front-end
PolymorphicEmbed.get_polymorphic_type(Reminder, :channel, SMS) == :sms
```

To get the module for a specific type, use:

```elixir
PolymorphicEmbed.get_polymorphic_module(Reminder, :channel, :sms) == SMS
```

### `traverse_errors/2`

The function `Ecto.changeset.traverse_errors/2` won't include the errors of polymorphic embeds. You may instead use `PolymorphicEmbed.traverse_errors/2` when working with polymorphic embeds.
Expand Down

0 comments on commit 8b9ff8a

Please sign in to comment.