# need help using will\_paginate with tagging

**URL:** <https://discuss.rubyonrails.org/t/need-help-using-will-paginate-with-tagging/26735>\
**Category:** rubyonrails-talk\
**Created:** [March 23, 2008, 3:34pm UTC](https://discuss.rubyonrails.org/t/need-help-using-will-paginate-with-tagging/26735 "2008-03-23T15:34:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sthapit](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sthapit](https://discuss.rubyonrails.org/u/sthapit)\
**Post date:** [March 23, 2008, 3:34pm UTC](https://discuss.rubyonrails.org/t/need-help-using-will-paginate-with-tagging/26735/1 "2008-03-23T15:34:12Z")

</div>

I have a simple tagging system:

places(id, title) taggings(id, place\_id, tag\_id) tags(id, title)

I can do the following sql to find places that are tagged as 'cheap' AND tagged as 'sushi':

select \* from places inner join taggings on taggings.place\_id = places.id and taggings.tag\_id in (select id from tags where title = 'cheap' or title = 'sushi') group by places.id having count(\*) = 2

I'm trying to do the same or similar query using will\_paginate - can someone help? This sort of works:

Place.paginate(:per\_page =\> 10, :page =\> 1, :include =\> [:taggings, :tags], :conditions =\> "taggings.tag\_id = tags.id and taggings.tag\_id in (select id from tags where title = 'cheap' or title = 'sushi')", :group =\> "places.id having count(\*) = 2")

The problem with this query is that if a certain tag does not exist I get a Mysql error. For example if someone searches with:

Place.paginate(:per\_page =\> 10, :page =\> 1, :include =\> [:taggings, :tags], :conditions =\> "taggings.tag\_id = tags.id and taggings.tag\_id in (select id from tags where title = 'cheap' or title = 'asdfsadf')", :group =\> "places.id having count(\*) = 2")

It gives, ActiveRecord::StatementInvalid: Mysql::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 'having count(\*) = 2

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 24, 2008, 2:35am UTC](https://discuss.rubyonrails.org/t/need-help-using-will-paginate-with-tagging/26735/2 "2008-03-24T02:35:28Z")

</div>

Vince,

I think you want to do a join like this

Articles.find(:all, :conditions =\> ..., &nbsp;&nbsp;&nbsp;&nbsp;:joins =\> "LEFT JOIN authors ON articles.author\_id=authors.id")

thank you can you can use those table(s) in your :conditions

Arshak

vince wrote:
