# Conditionally construct map

**URL:** <https://forum.elixirforum.com/t/conditionally-construct-map/64613>\
**Category:** Questions\
**Tags:** ecto, maps, phoenix\
**Created:** [July 1, 2024, 4:25am UTC](https://forum.elixirforum.com/t/conditionally-construct-map/64613 "2024-07-01T04:25:53Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![dimitarvp](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/32/38664_2.png) [@dimitarvp](https://forum.elixirforum.com/u/dimitarvp)\
**Post date:** [July 1, 2024, 9:49am UTC](https://forum.elixirforum.com/t/conditionally-construct-map/64613/3 "2024-07-01T09:49:23Z")

</div>

You can pattern match on `Ecto.AssocNotLoaded` and then have the map construction not include the key in that clause, or you can put `nil` and then have `Enum.reject` that deletes any map pairs with a `nil` value. Either one would be just fine.

---

_[View the full topic](https://forum.elixirforum.com/t/conditionally-construct-map/64613)._
