Hi - need some help to pin this one.
Am upgrading a project to 2.3.2. Have changed has_finder to named_scope. But I am getting an invalid mysql syntax error with a finder that used to work
I have:
Batch has_many :orders has_many :line_items, :through=>:orders
Order has_many :line_items
LineItem named_scope :unmatched, :conditions => {'product_id'=>0}
@batch.line_items.unmatched.any? gives me: 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_line_items_all FROM `line_items` INNER JOIN `orders` ON `line_items`' at line 1: SELECT count(`line_items`.*) AS count_line_items_all FROM `line_items` INNER JOIN `orders` ON `line_items`.order_id = `orders`.id WHERE (((`line_items`.`product_id` = 0) AND ((`orders`.batch_id = 1479))) AND ((`orders`.batch_id = 1479)))
If I run the query, I can make it work with count(*) or count (line_items.id) - is this a mysql problem? Also note the batch id condition is included twice.
If I do @batch.line_items.any? I get a valid query: SELECT count(*) AS count_all FROM `line_items` INNER JOIN `orders` ON `line_items`.order_id = `orders`.id WHERE ((`orders`.batch_id = 1479))
So am I doing something bad with my named_scope??
Thanks for any help Tonypm