在连接其他表时,我无法填充键的列表,所以我想知道我的模型是否正确,以及我尝试使用Thinky完成的操作是否可行,以下是我的代码:
组模型
var Group = thinky.createModel('group', {
users: [thinky.type.string()],
place_id: thinky.type.string()
});用户模型
var User = thinky.createModel('user', {
name: thinky.type.string()
});放置模型
var Place = thinky.createModel('place', {
name: thinky.type.string()
});
Place.hasMany(Group, "groups", "id", "place_id");我想获取一个place_id的所有带有用户名和地名的groups
下面是我所做的:
Place.get(PLACE_ID).getJoin({groups: true}).then(function(g){console.log(g);});如何填充用户名?使用_apply?怎么做到的?
发布于 2015-11-10 17:22:54
终于从Thinky的主人那里得到了答案:)
Thinky确实以SQL的方式连接。请参阅http://thinky.io/documentation/relations/
如果一个用户可以属于多个组:
var Group = thinky.createModel('group', {
id: thinky.type.string(),
place_id: thinky.type.string()
});
var User = thinky.createModel('user', {
id: thinky.type.string()
name: thinky.type.string()
});
var Place = thinky.createModel('place', {
name: thinky.type.string()
});
Place.hasMany(Group, "groups", "id", "place_id");
Group.hasAndBelongsToMany(User, 'users', 'id', 'id');
Place.get(PLACE_ID).getJoin({groups: {users: true}}).then(function(g){
console.log(g);
})希望能有所帮助。
https://stackoverflow.com/questions/33598891
复制相似问题