Featured

About this Blog

This site does not store any files on its server.
We only index and link to content provided by other websites.

[Rails] repeated conditions in sql queries

This is a minor question, mostly for curiosity: using rails 2.3, does
anybody else notice repeated conditions in sql queries?

consider the following app with two models linked through a join
table:


class User < ActiveRecord::Base
has_many :boxes_users
has_many :boxes, :through => :boxes_users
end

class Box < ActiveRecord::Base
named_scope :brown, :conditions => {:color => 'brown'}
end

class BoxesUser < ActiveRecord::Base
belongs_to :box
belongs_to :user
end


If I run this query:
>> User.find(1).boxes.brown

The following SQL is generated:

SELECT "boxes".* FROM "boxes" INNER JOIN "boxes_users" ON "boxes".id =
"boxes_users".box_id WHERE (("boxes_users".user_id = 1)) AND
(("boxes"."color" = 'brown') AND (("boxes_users".user_id = 1)))


Note that the ("boxes_users".user_id = 1) condition is repeated in the
sql query. Think does not impact the query results (though it does
makes parsing the development log a bit more tedious). Just curious
if anyone knows if this could potentially lead to less efficient
database queries in some circumstances, or have other secondary
effects?

--~--~---------~--~----~------------~-------~--~----~
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: