sailsjsを初めて使用しています。アプリケーションのバックエンドをsailsjsに変更しようとしています。私が使用する必要のある既存のデータベースを用意してください。この空の誤差は1対多の関連付けを使用しようと行き方:Sailsjs 1対多の空の結果
table user
id | name
1 | Someone
table new_car
name | user_id
Audi | 1
BMW | 1
モデル:: (私は、ネーミング・わからないです
{
"Result": [
{
"newCars": [],
"name": 'Someone',
"id": 1
}
]
}
はこれらは私が持っている2つのサンプルのテーブルの構造であり、
:コレクション、協会及び経由)//UserController.js
module.exports = {
tableName: 'user',
attributes: {
name: {
type: 'string'
},
newCars: { //i can name this anything?
collection: 'newCar', //should this be new_car (table name)?
via: 'user' //this is one-side table name?
}
},
autoCreatedAt: false,
autoUpdatedAt: false
};
//NewCarController.js
module.exports = {
tableName: 'new_car',
attributes: {
name: {
type: 'string'
},
users: {
model: 'User'
}
},
autoCreatedAt: false,
autoUpdatedAt: false
};
コントローラ - の
コメントにもいくつか質問があります。
ありがとうございますが、変更後の運はまだお勧めしません。私のテーブル構造とあなたのコメントを見て、 'via'は 'user'または 'user_id'でなければなりません。それでもuser_idに変更しようとしましたが、結果は空です。( – aiiwa
は 'Sails'アダプタによって作成された' user_id'フィールドですか? –
いいえ、私のデータベースはsailsjsを試用する前の状態です。 – aiiwa