Guest User

Untitled

a guest
Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. def get_user_items(options={}, limit = 10, offset = 0)
  2. # defaults
  3. params = {
  4. :conditions => ['(items.deleted = ? OR items.deleted IS NULL) AND (items.already_purchased = ? OR items.already_purchased IS NULL)', false, false],
  5. :limit => limit,
  6. :offset => offset,
  7. :order => 'items.date_added_to_list DESC',
  8. :include => [{:amazon_item => [:yahoo_item, {:taggings => :tag}]}, :amazon_item]
  9. }
  10.  
  11. # merge the conditions
  12. if conditions = options.delete(:conditions) and !conditions.first.blank?
  13. params[:conditions] = [
  14. "(#{params[:conditions][0]}) AND (#{conditions[0]})",
  15. *(params[:conditions][1..-1] + conditions[1..-1])
  16. ]
  17. end
  18. # merge the rest of the params
  19. params.merge!(options)
  20. # do the find
  21. items.find(:all, params)
  22. end
Add Comment
Please, Sign In to add comment