Mark For Destruction
> user = User.first
#=> #<User...>
> user.articles.each { |a| a.mark_for_destruction if a.id.odd? }
#=> [#<Article...>, ...]
> user.articles.find(1).marked_for_destruction?
#=> true
> user.articles.find(2).marked_for_destruction?
#=> false> user.save
(0.2ms) BEGIN
User Exists (0.8ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'person1@example.com' AND "users"."id" != 1) LIMIT 1
SQL (3.0ms) DELETE FROM "articles" WHERE "articles"."id" = $1 [["id", 1]]
SQL (0.2ms) DELETE FROM "articles" WHERE "articles"."id" = $1 [["id", 3]]
(2.1ms) COMMIT
=> trueclass User < ActiveRecord::Base
has_many :articles, autosave: true
endLast updated