I''ve run across this before - there''s a ticket on Lighthouse
about it,
but it''s eluding me at the moment.
If you''re really feeling adventurous, you can try your hand at fixing
it. I don''t get the sense that it''s a super-high priority,
given that
any decent query optimizer on the DB side is going to figure out that
the condition is duplicated and drop it.
--Matt Jones
On Nov 16, 2:50 pm, eugenio
<eugenio.mode...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> suppose we got two models: category and article.
> category has_many articles, article belongs_to category
>
> article has a named_scope defined by
> named_scope :online, :conditions => {:state => 2}
>
> in the controller i want to search for online articles that belongs to
> a given category. i tried this query:
> @category.articles.online.find(params[:id))
> it works, but it duplicates the condition about the category in the
> generated SQL:
> SELECT * FROM "articles" WHERE
("articles"."id" = 6 AND
> ("articles".category_id = 1)) AND
(("articles"."state" = 2) AND
> ("articles".category_id = 1))
>
> am i missing something?