所以我之所以感到困惑,是因为我是一名PHP开发人员并且使用过很多Laravel和FuelPHP
我真正理解的是它自己的关联.
我的意思是,我想创建一个基本的hasOne/BelongsTo逻辑,具体如下
用户有一个个人资料
个人资料属于用户
我习惯了下面的建立(Laravel风格)
用户表
id | username | email | password
---------------------------------------
1 | My Username | My email | 1234568
Run Code Online (Sandbox Code Playgroud)
Users_profile表
user_id | first_name | last_name
----------------------------------------
1 | My First name | My Last name
Run Code Online (Sandbox Code Playgroud)
然后我就这样定义了模型
用户模型
class Users extends Eloquent
{
public function profile()
{
return $this->hasOne('profile');
}
}
Run Code Online (Sandbox Code Playgroud)
档案模型
class Profile extends Eloquent
{
protected $tableName = 'users_profile';
protected $primaryKey = 'user_id';
public function user()
{
return $this->belongsTo('User');
}
}
Run Code Online (Sandbox Code Playgroud)
它只是工作,因为return $this->hasOne('profile'); …
我在理解从Sails.js客户端控制器发送socket.io事件并在服务器端控制器中处理它们的概念时遇到问题.首先,我使用npm下载了SailsJS项目框架,结构如下:
项目:
api
--adapters
--controllers
----server_userController.js
--models
--polices
--services
assets
--[styles, views, images, bower_components, and etc]
--js
----controllers
------userController.js
----app.js
----sails.io.js
----socket.io.js
config
node_modules
views
Run Code Online (Sandbox Code Playgroud)
我在"assets/js/controllers/server_userController.js"中写了以下内容:
socket.emit('getUser', {
_id: 10
});
Run Code Online (Sandbox Code Playgroud)
现在,如何指定哪个服务器端控制器负责处理此事件,以及如何处理?我希望在"api/controllers/server_userController.js"中收到此事件.所以,这样的东西将在控制器中:
module.exports = {
//Handling socket request here
//Emitting socket request
};
Run Code Online (Sandbox Code Playgroud)
提前致谢
嗨,我目前正在使用风帆我的休息api应用程序.我正在阅读以下文章 http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips-linkedin-mobile
在第2点,建议摆脱套接字池
var http = require('http');
var options = {.....};
options.agent = false;
var req = http.request(options)
Run Code Online (Sandbox Code Playgroud)
在第7点,它建议通过删除来摆脱会话.
app.use(express.session({ secret: "keyboard cat" }));
Run Code Online (Sandbox Code Playgroud)
我想知道我怎么能在风帆中做到这一点.
我正在将CSV文件上传到sails应用程序.此时它应该做两件事:
我的第一个想法是我能做点什么
entries = parse(data);
foreach(entry in entries) {
sails.models.entry.create(entry);
}
Run Code Online (Sandbox Code Playgroud)
但这种方法默默地失败了.
有没有一种正确的方法来处理这种情况?
谢谢!