6

I have basically the following code:

ModelA.join(:modelB).update_all('modelA.column = modelB.column')

That fails with:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "modelB"
LINE 1: ..." SET modelAs.column = modelBs...
                                                         ^
UPDATE "modelAs" SET modelAs.column = modelBs.column WHERE "modelAs"."id" IN (
  SELECT "modelAs"."id" FROM "modelAs" INNER JOIN "modelBs" ON "modelBs"."id" = "modelAs"."modelB_id"
)

Looking at the generated sql request, it is pretty obvious that Postgresql expects the modelB table to appear in the update part of the query. It there a way to do that or is it a bug?

(The issue is specific to Postgresql / the Postgresql rails adapter. The code above works fine with MySQL, the joins clause are also copied in the update part of the request)

Such
  • 910
  • 1
  • 9
  • 20

0 Answers0