[英]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.相同的逻辑适用于按
id
或name
排序,但不适用于现有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.