SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to get acts_as_taggable and paginating_find to play nicely...

    I've been playing with paginating_find today and it's pretty nice. Now the problem I'm having is that I want to paginate some results while using the find_tagged_with method of acts_as_taggable.

    So...

    The usual queries I've been building to use paginating_find have been along the lines of:

    Code Ruby:
    @images = Image.find :all, 
      :order => 'created_at DESC', 
      :page => {
        :size => 25,
        :current => params[:page]
      }

    Which works fine. The query that's used by find_tagged_with is as follows:

    Code Ruby:
    def find_tagged_with(list)
      find_by_sql([
        "SELECT #{table_name}.* FROM #{table_name}, tags, taggings " +
        "WHERE #{table_name}.#{primary_key} = taggings.taggable_id " +
        "AND taggings.taggable_type = ? " +
        "AND taggings.tag_id = tags.id AND tags.name IN (?) ",
        acts_as_taggable_options[:taggable_type], list
      ])
    end

    How could I edit the last query to be in the same kind of format as the first? I need to use the age = { :size = x, :current => y } for paginating_find to work?

    Any help would be awesome.
    hmm...

  2. #2
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the following:

    Code Ruby:
    def find_tagged_with(list, options = {})
      options[:size] = 25 if options[:size].blank?
      options[:current] = 1 if options[:current].blank?
     
      find :all,
        :select => "SELECT #{table_name}.* FROM #{table_name}, tags, taggings",
        :conditions => ["#{table_name}.#{primary_key} = taggings.taggable_id and taggings.taggable_type = ? and taggings.tag_id = tags.id AND tags.name IN (?)", acts_as_taggable_options[:taggable_type], list],
        :page => {
          :size => options[:size],
          :current => options[:current]
        }
    end

    But got the error:

    Mysql::Error: #42S22Unknown column 'taggings.taggable_id' in 'where clause': SELECT... snip
    Do I need to perform some kind of JOIN?
    hmm...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •