Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 第二列按不工作的rails postgres排序_Ruby On Rails_Postgresql_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 第二列按不工作的rails postgres排序

Ruby on rails 第二列按不工作的rails postgres排序,ruby-on-rails,postgresql,ruby-on-rails-4,Ruby On Rails,Postgresql,Ruby On Rails 4,我有一个疑问: 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.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
类配置文件{where.not(“元数据@>'linkedin\u用户名=>null')}
范围:facebook\u found,->{where.not(“元数据@>'facebook\u用户名=>null'))
作用域:twitter\u found,->{where.not(“元数据@>'twitter\u用户名=>null')}
范围:搜索关键字,->(关键字){where(“元数据->'bio'ILIKE?”,“%{keyword}%”
掠夺者:生物做的|父母|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'bio')
终止
洗劫者:主题做|父|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'topics')
终止
洗劫者:头衔做父母|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'title')
终止
洗劫者:性别做父母|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'gender')
终止
洗劫者:公司做的|母公司|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'company')
终止
搜掠者:推特的追随者做父母|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'twitter_followers')
终止
洗劫者:klout|u score do |父母|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'klout_score')
终止
洗劫者:facebook|u用户名do |家长|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'facebook_username')
终止
搜刮者:twitter|u用户名do |家长|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'twitter_username')
终止
搜刮者:linkedin|u用户名do |父|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'linkedin_username')
终止
洗劫者:位置做|父|
Arel::Nodes::InfixOperation.new('->',parent.table[:meta_data],'location')
终止
终止

您的配置文件模型中是否有一些默认的\u范围?在问题中添加了该模型。您可以将
附加到\u sql
的末尾,以获取Rails生成的sql查询,这可能有助于调试问题。我一眼就看不出模型有什么问题。
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")