2012-02-14 51 views
0

我已经做了这种类型的语句很多次,但它现在告诉我,该语句是模糊的。以下是错误:Activerecord语句“模棱两可”,但似乎没有错误

Mysql::Error: Column 'created_at' in where clause is ambiguous: SELECT  COUNT(DISTINCT `tasks`.`id`) AS count_id FROM  `tasks` LEFT OUTER JOIN `users` ON `users`.`id` = `tasks`.`author_id` WHERE  (created_at >= '2012-01-14 18:38:29') 

这里声明:

Task.count(:conditions => ["created_at > ?", 1.month.ago]) 

什么我错在这里做什么?

+2

你可能已经定义了一个默认范围,并在其中包含'users'。一些影响:'default_scope includes(:users)' – Swanand 2012-02-14 19:00:34

+0

对不起,为什么default_scope包含(:users)会导致模糊查询?我也碰到过这个。 – 2012-06-26 09:54:51

回答

5

尝试:

Task.count(:conditions => ["tasks.created_at > ?", 1.month.ago]) 

你的表可能有一个created_at所以你一定要指定要在查询中定位的表。

相关问题