post.js
649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import bookshelf from './base';
import User from './user';
import Tag from './tag';
/**
* @class Post
* @extends bookshelf.Model
*/
export default class extends bookshelf.Model {
/**
* 依赖表,删除时依据此项删除关联表中对应的数据
* @static {array}
*/
static dependents = ['tags'];
/**
* 表名称
* @return {string}
*/
get tableName() {
return 'posts';
}
/**
* One-to-many
* @return {bookshelf.Collection}
*/
user() {
return this.belongsTo(User);
}
/**
* Many-to-many
* @return {bookshelf.Collection}
*/
tags() {
return this.belongsToMany(Tag);
}
};