gpt4 book ai didi

ruby-on-rails - rails | PG::分组错误

转载 作者:行者123 更新时间:2023-11-29 14:35:39 25 4
gpt4 key购买 nike

<分区>

我有 cars 和 car_cities 模型。我想获得至少拥有一辆车的城市。

协会;

Cars
belongs_to :car_city

CarCities
has_many :cars

连接查询;

CarCity.joins(:cars).group("cars.car_city_id").having("count(cars.id) > 0")

这适用于我的本地环境。但不从事生产工作。

错误;

An ActionView::Template::Error occurred in search#search_city:

PG::GroupingError: ERROR: column "car_cities.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT “car_cities".* FROM "car_cities” INNER JOIN "cars"…

^
: SELECT “car_cities".* FROM “car_cities” INNER JOIN “cars” ON “cars"."car_city_id” = “car_cities"."id” WHERE "car_cities"."car_country_id” = $1 GROUP BY cars.car_city_id HAVING count(cars.id) > 0

app/views/search/_search_filters.html.erb:88:in `block in _app_views_search__search_filters_html_erb__3215729544581234245_70286113854020'

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com