Using join column value in update_all

Is it possible to use a field from a join in an update.

I’m trying to do something like this:

    Repo.update_all(
      from(m in Model,
        join: s in subquery(model_scores_query), on: s.model_id == m.id),
        update: [set: [weight: s.weight_score]]
      )

I want the ‘weight’ field of model to be set to the subquery’s ‘weight_score’ value but the compiler gives the following error in the ‘update: [set: [weight: s.weight_score]]:’ line

error:undefined function s/0

1 Like

Hmm, seems odd that that wouldn’t work, maybe you could just use a fragment to try to ‘coerce’ it? Maybe instead of s.weight_score try fragment("?", s.weight_score) or something? Sounds like a bug though?