gpt4 book ai didi

ruby-on-rails - Rails ActiveRecord:PG::错误:错误:列引用 "created_at"不明确

转载 作者:数据小太阳 更新时间:2023-10-29 06:30:27 26 4
gpt4 key购买 nike

我正在努力解决对象中的错误,但完全不确定问题出在哪里。

这是模型的样子:

class Car < ActiveRecord::Base  
has_many :car_colors
has_many :colors, :through => :car_colors
end

class CarColor < ActiveRecord::Base
belongs_to :color
belongs_to :car
end

class Color < ActiveRecord::Base
has_many :car_colors
has_many :cars, :through => :car_colors
end

这里是查询:

@cars = Car.all(:joins => :car_colors, :conditions => { :car_colors => {:color_id => params[:id_number]}}, :order => "cars.created_at DESC")

错误输出:

PG::Error: ERROR:  column reference "created_at" is ambiguous
LINE 1: ...d" WHERE "car_colors"."color_id" = 2 AND (created_at...
^
: SELECT "cars".* FROM "cars" INNER JOIN "car_colors" ON "car_colors"."car_id" = "cars"."id" WHERE "car_colors"."color_id" = 2 AND (created_at > '2013-05-03 12:28:36.551058') ORDER BY cars.created_at DESC

生成的 SQL 查询(在错误消息下方)似乎没有问题,但是是什么导致了错误消息?

提前谢谢你。

最佳答案

car_colors 表中可能有一个 created_at 字段。 created_at 可能应该是 cars.created_at 以消除歧义。

关于ruby-on-rails - Rails ActiveRecord:PG::错误:错误:列引用 "created_at"不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16896937/

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