Changeset for combined relations


#1

Hi! In this video: https://youtu.be/HVBkcq_7gJI?t=31m41s, you have used a create changeset for a combined relation. The case is trivial, I have 2 sql tables with one-to-many relationship. The relation schemas are infered and the associations are set with aliases belongs_to and has_many. Running the code from your video doesn’t work as expected. It just creates the parent to the database, but the nested data doesn’t. No errors raised. Am I missing something or it just doesn’t work for sql tables and I have to use only changsets for every relation?


#2

Can you provide a reproduction script?


#3
  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]
    ;# new_user = { name: "Jim", tasks: [{desc: "test"}, {desc: "test1"}]}
     def create(new_user)
        users.transaction do
           users.combine(:tasks).changeset(:create, new_user).commit
       end
     end
  end

#4

Looks like we have a bug. Could you report it as an issue?