0

I want to take the current Profile that's set under User and move it to the front of the ordered list. Is there a way to do this in a model scope, or even a specific query?

class Profile
  belongs_to :profileable, polymorphic: true
end

class User
  has_many :profiles, as: :profileable, dependent: :destroy

  # current_profile :integer
end

# This is the desired effect
profiles = current_user.profiles.to_a.delete_if {|i| i.id == current_user.current_profile}.unshift Profile.find(current_user.current_profile)
6ft Dan
  • 2,365
  • 1
  • 33
  • 46

1 Answers1

0

Try this query:

current_user.profiles.order("id != #{ current_user.current_profile.id }")
Alexander Karmes
  • 2,438
  • 1
  • 28
  • 34