Hi,

I have a named_scope that retrieves all the products for the current
website based on its domain name:
--
  named_scope :site, lambda { |website_name| { :joins => :site,
              :order => 'products.created_at DESC',
              :conditions => ['sites.domain_name = ?', website_name]}}
--

Then I would like to chain another named_scope to the previous one, so
that it adds one more condition to the query:
--
named_scope :single, lambda { |permalink| { :conditions => ['permalink =
?', permalink], :limit => 1 } }


Then in my controller I invoke:
--
@product = Product.site(website_name).single(params[:permalink])

And here is the SQL generated:
--
SELECT count(*) AS count_all FROM `products` INNER JOIN `sites` ON
`sites`.id = `products`.site_id WHERE ((products.permalink =
'demarrer-la-virtualisation-avec-xen') AND (sites.domain_name =
'digiprof.eu')) LIMIT 1
---


I don't know how in hell this count(*) made its way in the SQL!? Is this
a bug from named_scope? Everything works fine if there is only 1
named_scope in the chain that has a block of code.
-- 
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to