Reputation: 4617
I have attributes for sphinx as follows.
meeting_feedback_count = <<-SQL
SELECT meetings.*
FROM meetings
JOIN member_meetings mm
ON mm.meeting_id = meetings.id
JOIN meeting_feedbacks mf
ON mf.member_meeting_id = mm.id
GROUP BY meetings.id
SQL
has meeting_feedback_count, :as => :has_feedback, :type => :boolean
I execute the sql in mysql console, it seems to work fine. But i get the error. Is there any way around this,.
sql_range_query: 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 '*)
Upvotes: 0
Views: 769
Reputation: 16226
The error is happening because you're inserting a full SQL query into another SQL query. You only need to use the appropriate column(s) for the field or attribute you're adding.
If the model this index is for is Meeting, then you probably want something like this:
"COUNT(meeting_feedbacks.id) > 0", :as => :has_feedback, :type => :boolean
join feedbacks
The join method forces joins on the associations that you may refer to in SQL snippets.
Upvotes: 1