Greg Ma wrote:
> Colin Law wrote:
>> On 13 July 2010 10:36, Greg Ma <[email protected]> wrote:
>>>> Colin
>>>
>>> Yes I know that but I'm not trying to get Products but Categories with
>>> products
>>
>> I thought you meant "categories (along) with (their) products".
>> Do you mean that you want all the categories that have at least one
>> product, ie where category.products.count > 0?
>>
>> Colin
>
> That doesnt work either, that tells you if the current category has more
> than one products.
> And I want all the categories which has at least one product.
named_scope :with_products, lambda {
{
:select => "distinct categories.id",
:joins => "inner join categories_products on (categories.id =
categories_products.category_id)"
}}
It should be something like that, but this returns the categories id who
has products, and I want the ActiveRecord object not the ids...
--
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.