我有这个问题:
Profile.where(found: true).select("DISTINCT ON( profiles.id ) profiles.*, integration_profiles.data as integration_profiles_data, integrations.provider as integration_providers").reorder("profiles.id, profiles.email ")
我知道ID是截然不同的,这是一个显示问题的简单示例,但它不会按电子邮件排序,尽管它已包含在内。
一个更现实的例子:
Profile.where(found: true).select("DISTINCT ON( profiles.email ) profiles.*, integration_profiles.data as integration_profiles_data, integrations.provider as integration_providers").reorder("profiles.emai, profiles.age ")
现在它不会按年龄排序。
我的个人资料模型
class Profile < ActiveRecord::Base
has_many :integration_profiles
has_many :integrations, through: :integration_profiles
has_many :users, through: :integrations
scope :linkedin_found, -> { where.not("meta_data @> 'linkedin_username=>null' ") }
scope :facebook_found, -> { where.not("meta_data @> 'facebook_username=>null' ") }
scope :twitter_found, -> { where.not("meta_data @> 'twitter_username=>null' ") }
scope :search_keyword, ->(keyword) { where("meta_data -> 'bio' ILIKE ?", "%#{keyword}%") }
ransacker :bio do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'bio')
end
ransacker :topics do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'topics')
end
ransacker :title do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'title')
end
ransacker :gender do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'gender')
end
ransacker :company do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'company')
end
ransacker :twitter_followers do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'twitter_followers')
end
ransacker :klout_score do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'klout_score')
end
ransacker :facebook_username do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'facebook_username')
end
ransacker :twitter_username do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'twitter_username')
end
ransacker :linkedin_username do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'linkedin_username')
end
ransacker :location do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:meta_data], 'location')
end
end
答案 0 :(得分:0)
Profile.where(found: true).select("DISTINCT ON( profiles.email ) profiles.*, integration_profiles.data as integration_profiles_data, integrations.provider as integration_providers").reorder("profiles.email").order("profiles.age")