ユーザーモデルに接続されたUserControllerへのPOSTのサインアップフォームがあります。ユーザーは組織に所属しています。サインアップ中に新しい組織行が作成され、作成されたばかりのユーザーに適切な関係がセットアップされるようにしたい。これは、ユーザーの作成段階でSails/Waterlineで可能ですか?Sails.js /作成中のウォーターライン関連
signup.ejs
<h1>Signup</h1>
<form method="POST" action="/organization/users/">
<input type="email" name="email">
<input type="password" name="password">
<input type="text" name="organizationName">
<input type="submit" value="submit">
</form>
user.jsの(モデル)
module.exports = {
attributes: {
email: {
type: 'email',
required: true,
unique: true
},
password: {
type: 'string',
minLength: 6,
required: true
},
organization: {
model: 'organization'
}
}
};
UserController.js
module.exports = {
create: function (req, res) {
var options = {
name: req.param('email'),
password: req.param('password')
};
User.create(options).exec(function(err, user) {
return res.redirect("/users");
});
}
};
あなたは優れた答えを出しただけでなく、ウォーターラインがリクエストにキーを提供するだけで、関連するテーブルにレコードを作成することも知っていました。あなたの助けは本当に感謝しています。 PS、件名に関するあなたのコメントを反映するために質問を更新します。 – user1885523