Query to add edited entries to the top of a paginated list
Forums
»
Ruby - Ruby on Rails
>
Query to add edited entries to the top of a paginate...
Eric Hermann
#property_ids is an array of property id's that have been edited
edited_list_where = " WHERE properties.property_id IN (#{property_ids.join(', ')[0..-1]} )"
if(params[:page].to_i > 1)
property_limit = " LIMIT #{property_ids.length} OFFSET #{(params[:page].to_i*10)}" if (property_ids.length > 0)
end
Property.paginate_by_sql("(SELECT properties.*, layouts.* FROM properties
LEFT OUTER JOIN layouts ON layouts.property_id = properties.property_id
#{edited_list_where}
ORDER BY properties.modify_date ASC #{property_limit})
UNION
(SELECT properties.*, layouts.title FROM properties
LEFT OUTER JOIN layouts ON layouts.property_id = properties.property_id
WHERE properties.property_type='apartment' ORDER BY properties.property_status ASC)", :page => params[:page], :per_page => 10)
![]()
to hear about new tech videos/tutorials/posts.
All content in TechTalk and TechTV is licensed under Creative Commons License (non-commercial).
Please Share!