Forum: Ruby on Rails I need help in ActiveRecord..

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
String numecal validate! (Guest)
on 2006-04-20 01:16
I have this Product.find(:all, :include => [:brand, :category, :type],
:group =>
"description"), but it dont group by description why?


Bruno
Brian V Hughes (Guest)
on 2006-04-20 01:53
(Received via mailing list)
On Apr 19, 2006, at 05:16 PM, String numecal validate! wrote:
> I have this Product.find(:all, :include => [:brand, :category, :type],
> :group =>
> "description"), but it dont group by description why?

When ever you use :include in a fine, you have to disambiguate all of
your column references with the rest of the find options. So, if
description is part of products, then you have to do :group =>
"products.description", in order for it to work properly.

-Brian
Bruno (Guest)
on 2006-04-20 06:12
Brian V Hughes wrote:
> On Apr 19, 2006, at 05:16 PM, String numecal validate! wrote:
>> I have this Product.find(:all, :include => [:brand, :category, :type],
>> :group =>
>> "description"), but it dont group by description why?
>
> When ever you use :include in a fine, you have to disambiguate all of
> your column references with the rest of the find options. So, if
> description is part of products, then you have to do :group =>
> "products.description", in order for it to work properly.
>
> -Brian

That is not worked.I'am using this Product.find(:all, :include =>
[category], :group => "products.description")
And saw in log the query
SELECT products.`id` AS t0_r0, products.`entity_company_id` AS t0_r1,
products.`product_brand_id` AS t0_r2, products.`product_category_id` AS
t0_r3, products.`product_type_id` AS t0_r4, products.`code` AS t0_r5,
products.`description` AS t0_r6, products.`characteristics` AS t0_r7,
products.`cf` AS t0_r8, products.`cd` AS t0_r9, products.`cn` AS t0_r10,
products.`pisc` AS t0_r11, products.`icms` AS t0_r12, products.`ipi` AS
t0_r13, products.`mar` AS t0_r14, products.`active` AS t0_r15,
product_categories.`id` AS t1_r0, product_categories.`product_brand_id`
AS t1_r1, product_categories.`description` AS t1_r2,
product_categories.`active` AS t1_r3 FROM products LEFT OUTER JOIN
product_categories ON product_categories.id =
products.product_category_id



Thank's

Bruno
This topic is locked and can not be replied to.