2016-12-05 5 views
0

두 모델 : 사용자 및 InstalledApps. 모델은 다음과 같습니다돛 js에 많은 레코드 삽입 오류

//Users Model 
attributes:{ 
name: 'string', 
age: 'string', 
installedApps:{ 
    collection: 'installedApps', 
    via: 'users' 
} 
} 

내을 InstalledApps 모델은 다음과 같이이다 : 이미 ID 1과 2 그러나으로 사용자를 만든 지금

attributes:{ 
deviceID : 'string', 
users:{ 
    collection:'users', 
    via:'installedApps' 
} 
} 

내가 좋아하는 우체부를 통해을 InstalledApps에 데이터를 삽입 할 때 이 :

{ 
"users": [1,2], 
"deviceID": "123456", 
} 

오류 : Unknown rule: default가 나타납니다. 내가 어디가 잘못 됐는지 모르겠다.

답변

0

나는 모델을 잘못 만들었다 고 생각합니다. http://sailsjs.com/documentation/concepts/models-and-orm/associations/through-associations을 사용해야합니다. 그러면 3 가지 모델이 있어야합니다. USER, APP, INSTALLED_APPS.

사용자 모델은 얻을 것이다 :

//Users Model 
attributes:{ 
name: 'string', 
age: 'string', 
installedApps:{ 
    collection: 'APP', 
    via: 'user', 
through: 'installedApps' 
} 
} 

하고 APP 모델 :

//APP Model 
attributes:{ 
device: 'string', 
installedApps:{ 
    collection: 'APP', 
    via: 'app', 
through: 'installedApps' 
} 
} 

그리고 마지막으로 당신의 INSTALLED_APPS : 다음

//INSTALLED_APPS Model 
    attributes:{ 
    user: { 
     model: 'user' 
    }, 
    app: { 
     model: 'app' 
    } 
    } 

설치의 간단한 생성 사용 단지 것 모든 사용자/앱 또는 청사진 용 APP http://sailsjs.com/documentation/reference/blueprint-api/add-to

희망이 있습니다.

1

모델에 문제가 없습니다. JSON으로 데이터를 게시하고 있는지 확인 했습니까? 우편 번호의 Body 탭에서 을 JSON (application/json)으로 변경하십시오. "123456" 뒤에 잉여 쉼표를 제거하면 문제없이 문제가 해결됩니다. /installedApps 경로에 대한 POST 요청을하고 있는지 확인하십시오. http://localhost:1337/installedApps.

새 Sails.js 앱에 게시 한 모델 정의로이 테스트를 수행하여 installedApps 항목이 올바르게 삽입되어 users 항목과 연결되었습니다.

+0

실제로 'autoUpdateAt'도 json에서 보내므로 오류가 발생했습니다. 'autoUpdatedAt'는 보내지 않아야한다고 생각합니다. –

+0

@DevendraVerma 맞습니다.'createdAt'와'updatedAt'는 기본적으로 (config/models.js에서 전역 적으로 또는 모델 파일의 특정 모델에 맞게) 자동으로 처리됩니다. 다행히 문제가 해결되었습니다. =) – Viktor