I 모델의 다음과 같은 설정 :레일 has_many : 관습을 통해 foreign_key
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not exist: character varying = integer
LINE 1: ...".palette_color_id WHERE (("color_matches".hex = 66)) OR...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "palette_colors".* FROM "palette_colors" INNER JOIN "color_matches" ON "palette_colors".id = "color_matches".palette_color_id WHERE (("color_matches".hex = 66)) ORDER BY name ASC
이 날 액티브가 생성하는 쿼리를 사용하고 있음을 보여줍니다
class Cardstock < ActiveRecord::Base
has_many :color_matches, :primary_key => :hex, :foreign_key => :hex
has_many :palette_colors, :through => :color_matches
end
class ColorMatch < ActiveRecord::Base
belongs_to :palette_color
has_many :cardstocks, :foreign_key => :hex, :primary_key => :hex
end
class PaletteColor < ActiveRecord::Base
has_many :color_matches
has_many :cardstocks, :through => :color_matches
end
이 Cardstock.last.palette_colors
를 호출하면 다음과 같은 오류를 얻을 수 카드 용지의 ID (66
) 카드 스톡의 16 진수 (bbbbaf
)를 사용해야합니다. 대체로 hex
열을 사용하여 cardstocks
과 color_matches
사이에 가입하려면 ActiveRecord로 지정해야합니다. ActiveRecord가 이것을 지원합니까?
이것은 레일즈 2.3.x입니다. –