# Create nested entities for existing parent entity

**URL:** <https://discourse.rom-rb.org/t/create-nested-entities-for-existing-parent-entity/244>\
**Category:** Issues\
**Created:** [April 19, 2018, 6:12am UTC](https://discourse.rom-rb.org/t/create-nested-entities-for-existing-parent-entity/244 "2018-04-19T06:12:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drqCode](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/drqcode/32/160_2.png) [@drqCode](https://discourse.rom-rb.org/u/drqCode)\
**Post date:** [April 19, 2018, 6:12am UTC](https://discourse.rom-rb.org/t/create-nested-entities-for-existing-parent-entity/244/1 "2018-04-19T06:12:52Z")

</div>

```
  class Users < ROM::Relation[:sql]
       schema(:users, infer: true) do
           associations do
               has_many :tasks
           end
       end
end

  class Tasks < ROM::Relation[:sql]
      schema(:users, infer: true) do
         associations do
             belongs_to :user
        end
     end
end

  class UserRepo < ROM::Repository[:users]
    ;# update_data = { user_id: 123, tasks: [{desc: "test"}, {desc: "test1"}]}
     def update_user(update_data)
         users.transaction do
             users
                .tasks
                .by_user_id(update_data[:user_id])
                .changeset(:create, update_data[:tasks])
                .commit
         end
    end
 end

```

Hi! In the example above, I want to update the user with new tasks (this is how we say in our domain), but the tasks need user\_id (i don’t find a good solution making an operation just for merge user\_id for each task) for each item and using associate with changeset involves having the user struct. What is the proper way of handling this case with rom?

---

<div class="post-metadata">

**Author:** ![codeslinger](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@codeslinger](https://discourse.rom-rb.org/u/codeslinger)\
**Post date:** [May 10, 2022, 4:53pm UTC](https://discourse.rom-rb.org/t/create-nested-entities-for-existing-parent-entity/244/2 "2022-05-10T16:53:24Z")

</div>

Did you find a solution?
