MikeMarsian
MikeMarsian

Reputation: 638

find_by_sql fails with exception: wrong number of parameters

In the following code find_by_sql fails with exception: wrong number of parameters (0 for 1). Any idea what's going on?

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

Upvotes: 0

Views: 600

Answers (2)

Steve Jorgensen
Steve Jorgensen

Reputation: 12341

The way you wrote it, you are trying to execute find_by_sql with no arguments, and then call the [] operator on the result (but it failed before you got that far).

You need a space before the "[". To be even more clear, I would put parentheses around the array argument "...find_by_sql([...])".

Upvotes: 4

Ran
Ran

Reputation: 3523

Try adding brackets:

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])

Upvotes: 2

Related Questions