sql - multiple order statement rails -
i trying order posts. order posts randomly first, , these random posts should ordered no of upvotes.
i've tried:
@posts= @posts.order("random(), upvotes desc").limit(10)
but doesn't work. please help. thanks!
well, way this:
post.select("#{post.table_name}.*, random() rsort").order("rsort, upvotes desc").limit(10)
this says, select of columns in posts table column named resort (which random number between 0 , 1). order rsort column followed upvotes column. additionally should able access rsort attribute on model instance afterwards.
p.s. should come improve column name rsort.
sql ruby-on-rails
No comments:
Post a Comment