我正在使用Ruby on Rails 3.0.10,我试图在我的模型中实现scope
方法(比如模型A
),方法是调用另一个方法中存在的方法模型(比如模型B
)。也就是说,在A
我有:
scope :not_rel, lambda { |article, user| where("articles.id NOT IN (?)", article.find_owned_by(user).map(&:id)) }
find_owned_by
方法在B
中说明,用于搜索用户拥有的文章。但是,通过使用上面的代码,我收到ActiveRecord::StatementInvalid (Mysql2::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 'DISTINCT ...
错误。
所以,我的问题是:
是否可以在find_owned_by
命名范围内调用方法scope :not_rel
?
如何解决ActiveRecord::StatementInvalid
错误?
问题可能与模型中调用的map(&:id)
方法有关吗?