어떻게 연관을 동적으로 만들 수 있습니까? 예를 들어 :레일 : 동적으로 연관을 만드는 법
current_customer.company.association(:tenders).order('created_at DESC')
어떻게 연관을 동적으로 만들 수 있습니까? 예를 들어 :레일 : 동적으로 연관을 만드는 법
current_customer.company.association(:tenders).order('created_at DESC')
나는 다른 어떤 방법으로 연관성을 전달하고 싶습니다. (: METHOD_NAME, * 인수)
은 그래서
passed_in_association = :tenders
if([:tenders,:orders,:users].include?(passed_in_association)) #for security probably better to add it to a before filter.
current_customer.company.send(passed_in_association).order('created_at DESC')
end
나는 당신이하려는 정확히 모르겠지만 당신이 (이 결국 또 다른 방법입니다) 연결을 액세스 할 변수를 사용하려는 경우 당신은 send
를 사용할 수 있습니다
current_customer.company.send(:tenders).order('created_at DESC')
왜 이렇게할까요 것이다 송신이 당신이 찾는거야? ActiveRecord는 데이터 모델이 끊임없이 모양을 바꾸지 않는다고 가정합니다. – willglynn
내 앱용 서비스 계층을 구축하고 있습니다. 그래서 아래 예제처럼 CRUD를 처리하기위한 기본 서비스 클래스가 필요합니다. – Zeck