레일과 그 관계 쿼리 빌더에 대한 질문이 있습니다. 특히 관련 호출에 대해 어떻게 낙타 사례가 변환되는지에 대한 질문이 있습니다. 게터와 세터가 잘 작동ActiveRecord가 관계 CamelCase를 처리하는 방법
class CustomerPlan < ActiveRecord::Base
attr_accessible :customer_id, :plan_id, :startDate, :user_id
has_many :planActions
end
class PlanAction < ActiveRecord::Base
attr_accessible :actionType_id, :customerPlan_id, :notes, :timeSpent
belongs_to :customerPlan
belongs_to :actionType
end
관련 코드와 같은 plan_action.actionType.name
올바르게 관련 모델에서 가져옵니다. 열이 customerPlan_id
으로 데이터베이스에 정의되어
SQLite3::SQLException: no such column: plan_actions.customer_plan_id:
SELECT "plan_actions".*
FROM "plan_actions"
WHERE "plan_actions"."customer_plan_id" = 1
는이를 사용하는 난 그냥 잘못 그러나 customer_plan.planActions.each
오류를 반환? 다른 모든 호출에 대해 작동하며 다른 모든 관계가 정상적으로 작동합니다. 심지어 PlanAction -> CustomerPlan.
내가 모두 the docs을 조사하고 내가 아는 다른 모든 출처를 수색했다. 내 열을 변경하는 것은 간단 할 것입니다. 여기서 일어나는 일을 알고 싶습니다.
감사합니다.
빠른 수정은 foreign_key를 명시 적으로 설정하는 것입니다.
has_many :planActions, :foreign_key => "customerPlan_id", :class_name => "PlanAction"
그래도 어딘가에 모델 명명 규칙이 누락 된 것 같습니다. 무엇을 알아낼 수없는 것 같습니다.
정확히 내가 찾던 설명. 시간을내어 도와 주셔서 감사합니다! –