简体   繁体   English

Rails/Grape 应用程序中的排序错误 ActiveRecord::StatementInvalid PG::UndefinedColumn

[英]Sorting error ActiveRecord::StatementInvalid PG::UndefinedColumn in Rails/Grape app

I want to sort all Campaign by campaign_code in my admin panel, to do so I've created code below in my endpoint and serializer which front will be have in response.我想在我的管理面板中按campaign_code对所有Campaign 进行排序,为此我在我的端点和序列化程序中创建了下面的代码,前面将有响应。 The same logic works well for sorting by id or name but it wont worked for sorting of existing campagin_code number.相同的逻辑适用于按idname排序,但不适用于现有campagin_code编号的排序。

endpoint

optional :sort, type: Hash do
 optional :sort, type: Hash do
  optional :total, type: String, values: %w[asc desc]
 end
end

get do
  scoped_collection = scope_admin_resource(filter(Campaign.all))
  admin_serialize paginate(filter(sort(scoped_collection)))
end

serializer

class CampaignSerializer
  attributes :id, :total,

  attribute :total do |campaign|
    campaign.campaign_codes.count
  end
end

With that code I've an error:使用该代码我有一个错误:

ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column campaigns.total does not exist ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: 列campaigns.total不存在

There is no such column in campaigns table广告系列表中没有这样的列

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActiveRecord :: StatementInvalid:Rails中的PG :: UndefinedColumn - ActiveRecord::StatementInvalid: PG::UndefinedColumn in Rails ActiveRecord :: StatementInvalid:PG :: UndefinedColumn:错误 - ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR ActiveRecord::StatementInvalid PG::UndefinedColumn: 错误 - ActiveRecord::StatementInvalid PG::UndefinedColumn: ERROR ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:在Rails查询中 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: in rails query Rails抛出ActiveRecord :: StatementInvalid PG :: NotNullViolation:错误 - Rails throwing ActiveRecord::StatementInvalid PG::NotNullViolation: ERROR ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column rooms.hotel 不存在 LINE 1: - ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column rooms.hotel does not exist LINE 1: ActiveRecord :: StatementInvalid:PG :: UndefinedColumn:错误:.having('order_count> 5')时,列“ order_count”不存在 - ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column “order_count” does not exist when .having('order_count > 5') 为什么我在使用Postgresql的rails应用程序中使用布尔字段时收到ActiveRecord :: StatementInvalid:PG :: SyntaxError:ERROR? - Why am I receiving an ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR when using a boolean field in a rails app with Postgresql? Rails:使用ActiveRecord :: StatementInvalid失败的测试:PG :: NotNullViolation:错误 - Rails: Failing test with an ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:与HABTM与rails关联的关系 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation with HABTM association with rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM