HAS_MANY:通过_ids不能与条件

问题描述:

说我有过AuthorAssignment模型与许多作家一个Post模型工作:HAS_MANY:通过_ids不能与条件

​​3210

这里是我的问题:

当我打电话:

@post.featured_author_ids 

SQL查询不包含'author_assignments'.feature等于true的条件。

SELECT `author_assignments`.author_id FROM `author_assignments` WHERE (`author_assignments`.post_id = X) 

在另一方面,当我打电话:包括在SQL

@post.featured_authors 

条件和预期的结果是正确的。

想法?

+1

看起来像一个bug – fl00r 2011-04-06 18:29:08

+1

我在打开一个新的Rails票:https://rails.lighthouseapp.com/projects/8994/tickets/6680-has_many-through-_ids-not -passing-conditions-to-sql – chrisyour 2011-04-07 15:33:47

它可能与您正在使用的数据库相关,如SQLite等(不是MySQL)。 在这种情况下可以尝试:

:conditions=>["author_assignments.featured = ?",true] 
+0

对不起。没有运气。 ''只封装表名。当它被删除时,它不会改变条件未包含在SQL语句中的事实。 – chrisyour 2011-04-07 01:05:41

+0

你在哪个版本的导轨上? – 2011-04-07 05:22:43

+0

我正在使用Rails 3.0.6。 – chrisyour 2011-04-07 15:04:42