Bulk updating a joined table with ActiveRecord update_all and Rails 4
问题 I have a PostgreSQL query that I would like to write in ActiveRecord (Rails 4), but I'm having trouble getting it to work correctly. UPDATE chats AS c SET email = m.source_name FROM messages AS m WHERE c.id = m.chat_id AND m.created_at >= '2014-10-10' This is what I've tried: Chat.joins(:messages) .where("message.created_at >= '2014-10-10'") .update_all('chat.email = message.source_name') But it creates a query like this: UPDATE "chats" SET chat.email = message.source_name WHERE "chats"."id"