2016-10-18 5 views
0

자신의 하위 모델을 포함 할 수있는 모델을 연결하는 방법이 있습니까?waterline.js 동일한 모델 자체의 하위 모델을 가질 수있는 모델을 연결하는 방법은 무엇입니까?

{ 
identity: 'component', 
connection: 'default', 
attributes: { 
    id: { 
     type: 'string', 
     unique: true, 
     primaryKey: true, 
     required: true 
    }, 
    name: 'string', 

    from_device: { 
     model: 'device', 
     via: 'id' 
    }, 

    dataItems: { 
     collection: 'dataitem' 
    }, 

    subComponents:{ 
     collection: 'component', 
     via: 'id', 
     // through: 'componentsubcomponent' 
    } 
} 
} 

답변

0

년 OFC :

이 예에서 동일한 유형의 하위 구성 요소가있을 수 있습니다 '구성 요소'의 모델이있다. 그것은 예를 들어 중첩 된 주석을 작동합니다. 페이스 북에서.

예 :

// models/Comment.js 
module.exports = { 
    attributes: { 
    parent: { 
     model: "comment" 
    }, 
    children: { 
     collection: 'comment', 
     via: 'parent' 
    }, 
    content: { 
     type: "text", 
     required: true 
    }, 
    author: { 
     model: "user", 
     required: true 
    } 
    } 
};