[Rails] why does #destroy() DELETE FROM one at a time?
I have a pair of models with a fairly standard :has_many relation. The
only twist is that the has_many table is a namespaced STI table:
module MeteredService
class Base < ActiveRecord::Base
has_many :service_bills, :foreign_key => :metered_service_id,
:dependent => :destroy
...
end
end
class ServiceBill < ActiveRecord::Base
belongs_to :metered_service, :class_name => "MeteredService::Base",
:foreign_key => "metered_service_id"
...
end
When I do
my_metered_service.destroy
Rails generates individual DELETE FROM commands (and there are a lot of
them)
...
DELETE FROM "service_bills" WHERE "service_bills"."id" = $1 [["id",
633398]]
DELETE FROM "service_bills" WHERE "service_bills"."id" = $1 [["id",
633399]]
...
Question 1: Is this the expected behavior? I would think Rails would be
smart enough to do the deletions in a single statement along the lines
of:
DELETE FROM "service_bills" WHERE metered_service.id =
my_metered_service.id
Question 2: If this is NOT the expected behavior, have I set up my STI
relations incorrectly?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home