# \#nested-associations

**URL:** https://forum.elixirforum.com/tag/nested-associations/1144.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [Help defining URL Rest structure for nested element](https://forum.elixirforum.com/t/help-defining-url-rest-structure-for-nested-element/62617)

<div class="topic-metadata">

**Author:** [@joseratts](https://forum.elixirforum.com/u/joseratts)\
**Replies:** 5\
**Last updated:** [March 31, 2024, 10:34pm UTC](https://forum.elixirforum.com/t/help-defining-url-rest-structure-for-nested-element/62617 "2024-03-31T22:34:11Z")

</div>

Hello everyone I’m creating an example phoenix app just for learning. My example app is a real estate web portal, so I’m gonna publish places (houses, apartments, etc). I have defined the following entities Place (house…

---

## [Ecto Nested Preload Filter Referencing Top Level Assoc Join](https://forum.elixirforum.com/t/ecto-nested-preload-filter-referencing-top-level-assoc-join/60981)

<div class="topic-metadata">

**Author:** [@Nicemaker](https://forum.elixirforum.com/u/Nicemaker)\
**Replies:** 0\
**Last updated:** [January 15, 2024, 12:26am UTC](https://forum.elixirforum.com/t/ecto-nested-preload-filter-referencing-top-level-assoc-join/60981 "2024-01-15T00:26:30Z")

</div>

I have a nested preload with a has\_many relation and I would love to filter these references by a join I did on the top level, Here is my naive thinking: query = from vm in VariantMarket,as: :vm, left\_joi…

---

## [Advice on converting data structure into Ash resources](https://forum.elixirforum.com/t/advice-on-converting-data-structure-into-ash-resources/58643)

<div class="topic-metadata">

**Author:** [@yolo007wizard](https://forum.elixirforum.com/u/yolo007wizard)\
**Replies:** 6\
**Last updated:** [October 4, 2023, 8:47pm UTC](https://forum.elixirforum.com/t/advice-on-converting-data-structure-into-ash-resources/58643 "2023-10-04T20:47:35Z")

</div>

Wondering if anyone has advice on modelling this data structure in Ash resources: { "id": "123456", "name": "Rule - Lionel Messi sighting", "conditions": { "all": \[ { "pat…

---

## [Update nested struct with Ecto](https://forum.elixirforum.com/t/update-nested-struct-with-ecto/21128)

<div class="topic-metadata">

**Author:** [@helicon](https://forum.elixirforum.com/u/helicon)\
**Replies:** 6\
**Last updated:** [June 11, 2021, 4:13pm UTC](https://forum.elixirforum.com/t/update-nested-struct-with-ecto/21128 "2021-06-11T16:13:00Z")

</div>

Hello! I have 2 schemas: Asset and File. # asset schema has\_many :files, File # file schema belongs\_to :asset, Asset So it looks like: %Asset{ \_\_meta\_\_: #Ecto.Schema.Metadata\<:loaded, "assets"\>, id: 1, name…

---

## [Preload only first nested association's association](https://forum.elixirforum.com/t/preload-only-first-nested-associations-association/35577)

<div class="topic-metadata">

**Author:** [@Owens](https://forum.elixirforum.com/u/Owens)\
**Replies:** 8\
**Last updated:** [November 16, 2020, 12:00pm UTC](https://forum.elixirforum.com/t/preload-only-first-nested-associations-association/35577 "2020-11-16T12:00:05Z")

</div>

Hello all, I’m doing a DB call for the index page of a WhatsApp-style chat app. I have ChatsUsers → Chats → Messages. I need to get the list of the user’s chats ordered by recency of the last\_message, and just for the…

---

## [Testing models that cannot be created without long chain of dependancies. Tips?](https://forum.elixirforum.com/t/testing-models-that-cannot-be-created-without-long-chain-of-dependancies-tips/34652)

<div class="topic-metadata">

**Author:** [@woohaaha](https://forum.elixirforum.com/u/woohaaha)\
**Replies:** 3\
**Last updated:** [September 30, 2020, 3:11pm UTC](https://forum.elixirforum.com/t/testing-models-that-cannot-be-created-without-long-chain-of-dependancies-tips/34652 "2020-09-30T15:11:24Z")

</div>

Hi all, How do you write your context tests (create\_thingy(attrs)) when there are a lot of associations that need to be created first? Here is a contrived example. Let’s says I have a Door model that I’d like to test t…

---

## [Saving an association from a select input](https://forum.elixirforum.com/t/saving-an-association-from-a-select-input/34231)

<div class="topic-metadata">

**Author:** [@boggsey](https://forum.elixirforum.com/u/boggsey)\
**Replies:** 6\
**Last updated:** [September 8, 2020, 3:59pm UTC](https://forum.elixirforum.com/t/saving-an-association-from-a-select-input/34231 "2020-09-08T15:59:09Z")

</div>

Hey friends! I’m very new to Elixir and Phoenix and this community has been extremely helpful so far. Unfortunately, I am running into some issues with my understanding. I’m hoping someone can suggest some reading or poi…

---

## [Image upload using Arc and nested form](https://forum.elixirforum.com/t/image-upload-using-arc-and-nested-form/32010)

<div class="topic-metadata">

**Author:** [@Kapeusz](https://forum.elixirforum.com/u/Kapeusz)\
**Replies:** 2\
**Last updated:** [June 2, 2020, 12:03pm UTC](https://forum.elixirforum.com/t/image-upload-using-arc-and-nested-form/32010 "2020-06-02T12:03:12Z")

</div>

Hi, I have two models, Product and Category. After help I got from here I could add/edit a product with the chosen category, but now after I set up Arc I face same error again: assign @categories not available in eex te…

---

## [Validating a has\_many assoc changeset on update](https://forum.elixirforum.com/t/validating-a-has-many-assoc-changeset-on-update/27989)

<div class="topic-metadata">

**Author:** [@ion](https://forum.elixirforum.com/u/ion)\
**Replies:** 1\
**Last updated:** [January 5, 2020, 9:59pm UTC](https://forum.elixirforum.com/t/validating-a-has-many-assoc-changeset-on-update/27989 "2020-01-05T21:59:58Z")

</div>

I have a schema with a :has\_many resource that I cast\_assoc in the changeset function. On updates, I need to check the :insert\_at timestamp of any associated :has\_many resource that is being updated. Where and what is t…

---

## [Select element in a nested form](https://forum.elixirforum.com/t/select-element-in-a-nested-form/27729)

<div class="topic-metadata">

**Author:** [@wolfiton](https://forum.elixirforum.com/u/wolfiton)\
**Replies:** 7\
**Last updated:** [December 21, 2019, 2:05pm UTC](https://forum.elixirforum.com/t/select-element-in-a-nested-form/27729 "2019-12-21T14:05:19Z")

</div>

Hi everyone, I am getting an error when i try to add a select in a nested form The error no function clause matching in Keyword.pop/3 My select code: \<div class="field"\> \<%= label f, :category, class: "label" %\> \<…

---

## [Load nested association and select count at the same time](https://forum.elixirforum.com/t/load-nested-association-and-select-count-at-the-same-time/25017)

<div class="topic-metadata">

**Author:** [@abdelaz3r](https://forum.elixirforum.com/u/abdelaz3r)\
**Replies:** 9\
**Last updated:** [August 30, 2019, 3:32pm UTC](https://forum.elixirforum.com/t/load-nested-association-and-select-count-at-the-same-time/25017 "2019-08-30T15:32:20Z")

</div>

Hello. I have this Ecto Shema: Instance -\> has\_many(Faction) -\> many\_to\_many(Profils) So, instances has many factions, and profils can register into a faction (given an instance). I would like, when I load instances,…

---

## [Passing primary key down to nested struct using cast\_assoc](https://forum.elixirforum.com/t/passing-primary-key-down-to-nested-struct-using-cast-assoc/22121)

<div class="topic-metadata">

**Author:** [@deerob4](https://forum.elixirforum.com/u/deerob4)\
**Replies:** 0\
**Last updated:** [May 3, 2019, 9:15am UTC](https://forum.elixirforum.com/t/passing-primary-key-down-to-nested-struct-using-cast-assoc/22121 "2019-05-03T09:15:10Z")

</div>

I’m using cast\_assoc/3 to cast some nested associations in my changesets. The simplified schemas look like this: schema "trial" do has\_one :chief\_investigator, ChiefInvestigator has\_many :principal\_investigators, Pr…

---

## [Modifying a changeset with build\_assoc?](https://forum.elixirforum.com/t/modifying-a-changeset-with-build-assoc/19484)

<div class="topic-metadata">

**Author:** [@johnkacz](https://forum.elixirforum.com/u/johnkacz)\
**Replies:** 0\
**Last updated:** [January 17, 2019, 7:35pm UTC](https://forum.elixirforum.com/t/modifying-a-changeset-with-build-assoc/19484 "2019-01-17T19:35:19Z")

</div>

Howdy, I’m looking for some help with polymorphic associations and nested forms. I’m using formex (a great form library inspired by Symfony) and formex\_ecto which gives a modify\_changeset callback. I’m wanting to possib…

---

## [Nested association preloads doesn't work](https://forum.elixirforum.com/t/nested-association-preloads-doesnt-work/17502)

<div class="topic-metadata">

**Author:** [@dobrygin](https://forum.elixirforum.com/u/dobrygin)\
**Replies:** 5\
**Last updated:** [October 25, 2018, 11:01am UTC](https://forum.elixirforum.com/t/nested-association-preloads-doesnt-work/17502 "2018-10-25T11:01:39Z")

</div>

Hello! I have structure: Post → Author and Post → Shared → Author. But my nested associations for Author inside Shared doesn’t work. I got error: \*\* (KeyError) key :author not found in: #Ecto.Association.NotLoaded\<as…
