링크 테이블을 사용하여 작업을 사람과 관련시키는 테이블 구조가 있는데 링크 테이블에는 특정 작업이 얼마나 오래되었는지에 대한 데이터 정보가 들어 있습니다. 추가 정보가있는 링크 테이블을 사용하는 Activerecord
나는 모든 작업을 얻을 작업의 고용 날짜 범위를 표시하기 위해 노력하고 간단한 레일 응용 프로그램이 있습니다.class Employment < ActiveRecord::Base
belongs_to :person
belongs_to :job
end
class Job < ActiveRecord::Base
belongs_to :employer
has_many :employment
accepts_nested_attributes_for :employment
end
def index
@jobs = Job.joins(:employment).find(:all)
end
내가 액세스 할 때 이제 속성 'employment_started'/ I가 '경험 # 지수 NoMethodError'를 얻을 끝났다 나는 'to_yaml'기능을 사용하면 내가 볼 수
이undefined method `employment_started' for #<Class:0x000000026927e0>
17: <span><%=job.employment.employment_started%> - <%=job.employment.to_yaml%>
데이터가 객체에서 :
!ruby/object:Employment attributes: job_id: 1 person_id: 1 employment_started: 2008-04-21 employment_ended: attributes_cache: {} changed_attributes: {} destroyed: false marked_for_destruction: false new_record: false previously_changed: {} readonly: false
왜 3'rd 레벨 속성에 액세스 할 수 없습니까?
좋은 캐치, 롤 ... to_yaml이 형식을 컬렉션으로 표시하지 않는 이유는 무엇입니까? 동적 객체에 대한 정보를 덤프하는 더 쉬운 방법이 있습니까? –