在以下代码中,find_by_sql失败,异常:参数个数错误(0表示1)。 知道发生了什么事吗?
def filter_new_unfollowers(unfollower_ids)
relationships = TwitterRelationship.find_by_sql["SELECT * FROM twitter_relationships
INNER JOIN twitter_identities ON (twitter_identities.twitter_id=twitter_relationships.source_twitter_id)
INNER JOIN member_twitter_identities ON (member_twitter_identities.twitter_identity_id = twitter_identities.id)
WHERE member_twitter_identities.member_id IN (?)", unfollower_ids]
end
答案 0 :(得分:4)
你编写它的方式,你试图在没有参数的情况下执行find_by_sql,然后在结果上调用[]运算符(但是在你到达之前它失败了)。
在“[”之前需要一个空格。为了更清楚,我会在数组参数“... find_by_sql([...])”周围加上括号。
答案 1 :(得分:2)
尝试添加括号:
relationships = TwitterRelationship.find_by_sql(["SELECT * FROM twitter_relationships
INNER JOIN twitter_identities ON (twitter_identities.twitter_id=twitter_relationships.source_twitter_id)
INNER JOIN member_twitter_identities ON (member_twitter_identities.twitter_identity_id = twitter_identities.id)
WHERE member_twitter_identities.member_id IN (?)", unfollower_ids])