2010-04-14 3 views
1

PolyModel 기반 클래스를 SelfReferenceProperty로 사용할 수 있습니까?Google App Engine : PolyModel + SelfReferenceProperty

class BaseClass(polymodel.PolyModel): 
    attribute1 = db.IntegerProperty() 
    attribute2 = db.StringProperty() 

class ParentClass(BaseClass): 
    attribute3 = db.StringProperty() 

class ChildClass(BaseClass): 
    parent = db.SelfReferenceProperty(collection_name = 'children') 


p = ParentClass() 
p.attribute1 = 1 
p.attribute2 = "Parent Description" 
p.attribute3 = "Parent additional data" 
p.put() 

c = ChildClass() 
c.attribute1 = 5 
c.attribute2 = "Child Description" 
c.parent = p.key() 
c.put() 

이 코드를 실행하고 개발 서버의 관리 인터페이스를 통해 데이터 저장소를 확인하십시오

나는 아래의 코드가 있습니다. 부모 인스턴스가 데이터 저장소 class = 'BaseClass, ParentClass'에 저장되지만 자식은 저장되지 않습니다. 브라우저에 오류 출력이없고 (디버그가 켜져 있음) 내 앱의 실행기 로그에는 아무 것도 출력되지 않습니다.

이 작업을 수행 할 수 있습니까?

+0

이상한 - 추가 코드를 변경하지 않고도 이제 설명 할 수없는 신비가 작동합니다. – rvandervort

+0

폐쇄 된 것으로 표시 할 수 있습니까? –

답변

0

나는 여기서 아무것도 바꿀 수 없다는 거짓말입니다. 실제로 "parent"속성을 "parent_ref"로 변경해야했습니다. 또한 참조가 SelfReferenceProperty에서 ReferenceProperty (Parent, collection_name = 'children')로 변경 될 때까지 예상대로 작동하지 않았습니다.

하지만 결국 다형성 자체 참조가 작동합니다.