2012-08-29 2 views
1

저는 현재 외부 소스에서 데이터를 가져 오는 Padrino 프로젝트에서 Mongomapper를 사용하고 있습니다. 주 개체 (Application)에는 두 개의 연결된 문서 형식 인 ActivityNotice이 있습니다.몽고 마 외래 키?

그러나 내부 키를 사용하지 않고 외래 키를 직접 지정하고 싶습니다. 외래 키가 데이터 내보내기에 있으며, 이는 레이크 작업을 통해 가져옵니다.

나는 EmbeddedDocument을 시도했지만 관련 데이터를 업데이트하지 않고 삭제하는 것이 이상적입니다.

나는 다음을 시도했지만 운이없이 :

class Application 
    include MongoMapper::Document 
    ensure_index [[:latlng, '2d']] 

    key :refval, String 
    key :pkeyval, String 
    key :applicantname, String 
    key :latlng, Array 
    key :address, String 
    key :occupier, String 
    key :type, String 
    key :casetype, String 
    key :tradingname, String 
    key :closingdate, Date 
    key :recieveddate, Date 
    key :details, String 
    key :usetype, String 
    key :status, String 
    key :validfrom, Date 
    timestamps! 

    many :activities 
    many :notices 
end 

class Activity 
    include MongoMapper::Document 

    key :keyval, String 
    key :pkeyval, String 
    key :type, String 
    key :cycle, String 
    key :open, String 
    key :close, String 

    belongs_to :application, :foreign_key => :pkeyval 
end 

class Notice 
    include MongoMapper::Document 

    key :keyval, String 
    key :pkeyval, String 
    key :recieveddate, Date 
    key :startdate, Date 
    key :enddate, Date 
    key :days, String 
    key :hours, String 
    key :activities, Array 

    belongs_to :application, :foreign_key => :pkeyval 
end 

모든 아이디어를 어디서 잘못된거야?

답변

4

MongoMappers의 Associations documentation은 이것에 대해 약간 밝았지만 test_associations 기능 테스트에서 볼 수있는 예제가 있습니다. :foreign_key 정의는 belongs_to 대신 many에 지정해야합니다.

+0

그래, 고마워! 당신 말이 맞아요. 문서는 그 점에 관해서는 거의 말하지 않는 약간의 스케치입니다. 한 가지 더해야 할 일은'key : refval, String'을'key : _id, String'으로 변경하여 애플리케이션 객체의 기본 키를 오버라이드하는 것입니다. – Pezholio