0
我有兩個型號:更改主鍵和外鍵的ActiveRecord
class Settlement < ActiveRecord::Base
set_primary_key :settlement_identifier
has_many :streets
attr_accessible :city, :name, :service_available, :zip, :country_id,: settlement_identifier
end
class Street < ActiveRecord::Base
belongs_to :settlement, foreign_key: "settlement_identifier"
attr_accessible :name, :settlement_identifier, :street_identifier
end
因爲我做的街道和住區的進口,我需要通過settlement_identifier指向街道,不settlement_id。 當我做
Street.first.settlement #it compare settlement_identifiers from both tables
但是,當試圖從單結匯的街道,如:
Settlement.first.streets
它拋出一個錯誤
SELECT "streets".* FROM "streets" WHERE "streets"."settlement_id" = 4263
ActiveRecord::StatementInvalid: PG::Error: ERROR: column streets.settlement_id does not exist .
我希望該查詢是:
SELECT "streets".* FROM "streets" WHERE "streets"."settlement_identifier" = 4263
有什麼幫助嗎?