Setting an association by passing tuple rather than id

Is it possible to create associations in this manner?

tasks_repo.create({ id: 1, user: {id: 1, name: "Jane"}, title: "Jane's task" })

Not an Aggregate Write as the user tuple has an id and there is no combine.
OR do I have to use change sets:

task = tasks_repo.create(task_changeset.associate({id: 1, name: "Jane"}, :user))

Also I was wondering if an aggregate update can be done with change sets and if you can give reference to examples?

Many Thanks!

Repo command methods are very basic and don’t support combined commands, so you need to stick to changesets.

1 Like