5

레일 4.1.4에서 레일 4.2.0으로 업그레이드하기 시작합니다. 그것은 첫 번째처럼 보입니다! 일부 활성 레코드 연결에서 더 이상 지원되지 않습니다."처음!" AR CollectionProxy는 Rails 4.1.4에서 4.2.0으로 업데이트 한 후 "undefined method [] for nil"을 발생합니다.

first! (ActiveRecord :: Associations :: CollectionProxy)에서 지금 오류가 발생했습니다.

어떻게 동작을 수정하여 4.1.4에서와 같이 작동합니까?

레일 4.1 :

(byebug) user.organization.registration_codes 
#<ActiveRecord::Associations::CollectionProxy [#<RegistrationCode id: 259, code: "AWESOMESAUCE" ... >]> 

(byebug) user.organization.registration_codes.first! 
#<RegistrationCode id: 259, code: "AWESOMESAUCE" ... > 

레일 4.2 : 액티브로 파고

(byebug) user.organization.registration_codes 
#<ActiveRecord::Associations::CollectionProxy [#<RegistrationCode id: 259, code: "AWESOMESAUCE" ... >]> 

(byebug) user.organization.registration_codes.first! 
NoMethodError Exception: undefined method `[]' for nil:NilClass 
nil 

업데이트

, 나는 여기에 실패 찾을 :

def find_nth(index, offset) 
    if loaded? 
    @records[index] 
    else 
    offset += index 
    @offsets[offset] ||= find_nth_with_limit(offset, 1).first 
    end 
end 

loaded?은 true를 반환하지만 @records는 nil입니다. 디버거를 던지고 find_nth_with_limit(offset, 1).first을 호출하면 예상 한 레코드가 반환됩니다.

first!이 문제는 협회가로드를 생각하는 것 같다 defined in finder_methods.rb in active record이지만,이 레일의 회귀가

+0

첫 번째! 더 이상 사용되지 않는 것으로 보입니다. – Doon

+0

여기서'first!'가 정의되어 있습니까? 어떤 문서 나 출처에서 찾을 수 없습니까? – engineersmnky

+0

활성 레코드 파인더의 일부로 정의되며 더 이상 te 콜렉션 프록시에 정의되지 않은 것 같습니다. – Doon

답변

관련 문제