At least, it does for me.
Here's the setup:
class Category < ActiveRecord::Base
has_many :category_products, :dependent => :destroy
has_many :products, :through => :category_products
end
class Product < ActiveRecord::Base
has_many :category_products, :dependent => :destroy
has_many :categories, :through => :category_products
named_scope :active,
:conditions => ["products.active = ? and ( products.active_on is NULL or products.active_on = '' or products.active_on <= ?)",
true, Time.now
]
end
class CategoriesController < ApplicationController
def show
@category = Category.find(params[:id])
@products = @category.products.active.paginate( :page => params[:page], :per_page => 5 )
end
end
And the error I get is:
ActiveRecord::StatementInvalid in CategoriesController#show
Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) AS count_products_all FROM `products` INNER JOIN `categories_products` ON `pr' at line 1: SELECT count(`products`.*) AS count_products_all FROM `products` INNER JOIN `categories_products` ON `products`.id = `categories_products`.product_id WHERE (((products.active = 0 or ( products.active_on is not null and products.active_on != '' and products.active_on > '2009-03-16 15:03:46')) AND ((`categories_products`.category_id = 589))) AND ((`categories_products`.category_id = 589)))