major refactoring of post sets and pagination, incomplete

This commit is contained in:
albert
2011-06-03 19:47:16 -04:00
parent ce0695c606
commit ca3e9bb6db
21 changed files with 475 additions and 204 deletions

View File

@@ -117,16 +117,13 @@ class User < ActiveRecord::Base
end
module FavoriteMethods
def favorite_posts(options = {})
favorites_table = Favorite.table_name_for(id)
if options[:before_id]
before_id_sql_fragment = ["favorites.id < ?", options[:before_id]]
def favorites(options = {})
post_ids = Favorite.find_post_ids(id, options)
if post_ids.any?
Post.where("id in (?)", post_ids).order(Favorite.sql_order_clause(post_ids))
else
before_id_sql_fragment = "TRUE"
Post.where("false")
end
limit = options[:limit] || 20
Post.joins("JOIN #{favorites_table} AS favorites ON favorites.post_id = posts.id").where("favorites.user_id = ?", id).where(before_id_sql_fragment).order("favorite_id DESC").limit(limit).select("posts.*, favorites.id AS favorite_id")
end
end