2014-02-15 8 views
0

1 : n으로 주문과 관계가있는 간단한 모델 고객이 있습니다.관련 데이터가 저장되지 않음

class Customer 
    include Mongoid::Document 

    field :name, type: String 
    has_many :orders 

end 

이 코드 조각하는 rails4 콘솔에

customer = Customer.new name: "John" 
customer.orders.build item: "ipad" #=> doesn't work in the method create 
customer.save      #=> true 

작품 만 고객 이름이 저장되는 경우, 생성 방법에서 작동하지 않습니다,하지만 순서는하지와 같다 빌드 메소드가없는 경우. 결과적으로 항목 "ipad"는 저장되지 않으며 주문도 발생하지 않습니다.

저는 레일스 (4.0.2) + 몽고이드 (4.0.0.alpha1)를 사용하고 있습니다.

근본 원인은 무엇입니까? http://mongoid.org/en/mongoid/docs/relations.html

class Band 
    include Mongoid::Document 
    has_many :albums, autosave: true 
end 

band = Band.first 
band.albums.build(name: "101") 
band.save #=> Will save the album as well. 

건배를 통해

답변

1

!

+0

이것은 많은 도움이되지만 자동 저장 옵션이없는 콘솔에서 작동하는 이유는 무엇입니까? – canoe

관련 문제