I am facing a problem with will_paginate when doing a complicated find.
:photo has_many :tags, :through => :tagships
:item has_many :photos
:photo belongs_to :item
@photos = @item.photos.paginate :page => params[:page],
:per_page => 200,
:conditions => [ 'tags.id IN (?)', tag_ids],
:order => 'created_at DESC',
:joins => :tags,
:group => "photos.id HAVING COUNT(DISTINCT tags.id) = #{tag_count}"
I want to get all the photos that have all the tags in the tag_ids array. MySQL IN usually does a "or" search, but I need a "and". I found how to change IN to mimic the "and" behavior of here , and it works fine when using model.find (), also works as long as the number of posts is calculated below mine: per_page count. But if it should be paginated, the generated SQL is like:
SELECT count(*) AS count_all, photos.id HAVING COUNT(DISTINCT tags.id) = 1 AS photos_id_having_count_distinct_tags_id_1 FROM `photos`(...)
which does not work. Others saw this error and were able to transfer their account () from the request, but I do not think this is possible in my case.
, will_paginate? , , ?
!