2014-12-09 3 views
1

는 especailly이 :sailsjs - waterline이 mongodb를 현명한 방식으로 지원할 수 있습니까? 요즘 sailsjs에서와 documenation <a href="http://sailsjs.org/#/documentation/concepts/ORM/Models.html" rel="nofollow">http://sailsjs.org/#/documentation/concepts/ORM/Models.html</a><br> 보고 찾고 있었어요

// From api/models/Person.js... 

module.exports = { 
    attributes: { 
    // Primitive attributes 
    firstName: { 
     type: 'string', 
     defaultsTo: '' 
    }, 
    lastName: { 
     type: 'string', 
     defaultsTo: '' 
    }, 

    // Associations (aka relational attributes) 
    spouse: { model: 'Person' }, 
    pets: { collection: 'Pet' }, 

    // Attribute methods 
    getFullName: function(){ 
     return this.firstName + ' ' + this.lastName; 
    }, 
    isMarried: function() { 
     return !!this.spouse; 
    }, 
    isEligibleForSocialSecurity: function(){ 
     return this.age >= 65; 
    }, 
    encryptPassword: function() { 

    } 
    } 
}; 

이 객체의 배열 무거운 마음 SQL, 어떻게이 가질 수있는 속성을 것 같아? mongodb처럼. 예를 들어

어쩌면 내 사람 모델은 각 영화 당신은 모델 연결을 사용해야합니다

답변

3

자신의 이름과 길이가 영화의 배열 인 속성이라고 liked_movies 있습니다.
Salis docs about associations

요청하는 영화의 예에서는 many to many가 있습니다. 돛이 피봇 테이블을 만듭니다. 또한 해당 연결에 대한 URL과 같은 REST를 작성합니다. 즉 person/:personId/likedMovies