ARel silently ignoring "where" and "offset" clauses on updates


I've submitted some patches to ARel that (supposedly) fix the following bugs:

Before applying these patches, ARel has the following behaviour:

ruby > News.where("highlighted = ?",
=> false)
UPDATE "news" SET "highlighted" = 'f' WHERE "news"."id" IN (SELECT
"news"."id" FROM "news" ORDER BY highlighted_at LIMIT 1)

Note how both the where("highlighted = ?", true) and offset(1) clauses
are ignored. After the patches, it yields the following:
UPDATE "news" SET "highlighted" = 'f' WHERE (highlighted = 't') AND
"news"."id" IN (SELECT "news"."id" FROM "news" ORDER BY highlighted_at

Feedback on these would be appreciated.

Hugo Peixoto

I think the "WHERE (highlighted = 't')" part should be put in the inner query for this to work correctly.

The query you've shown us selects id of the first highlighted_at object. It might or might not pass the update condition and so the complete query will update one or no rows, even though further in the defined order there might be other rows that would pass the update condition.


I believe you are right. I'm replacing the patches.

Hugo Peixoto