0
나는 방법 has_one
관계를 확장하는 시도했다 :액티브`has_one` 협회 확장 방법
has_one :subscription_plan, -> { where current: true } do
def in newspaper
where newspaper: newspaper
end
end
및 오류 undefined method 'in' for #<SubscriptionPlan...>
있어하지만 has_many
와 함께 작동 :
has_many :subscription_plans, -> { where current: true } do
def in newspaper
where(newspaper: newspaper).take
end
end
Rails 4.2.1에서 has_one
으로 작동시키는 방법은 무엇입니까?
많이 좋아요! ActiveRecord 문서 http://guides.rubyonrails.org/association_basics.html#association-extensions는 다소 혼란 스럽습니다.'확장 기능은 proxy_association 접근 자의 세 가지 속성을 사용하여 연결 프록시의 내부를 참조 할 수 있습니다. ... proxy_association. target은 belongs_to 또는 has_one에 대한 연관된 객체 또는 has_many 또는 has_and_belongs_to_many에 대한 연관된 객체의 컬렉션을 반환합니다. 문서에서 'has_one'이 언급 된 것은 실수입니까? – yurko
나는 그것이 오류라고 생각하지 않지만, 지금은 주석을 달 수 없다. =) – Aleksey