2

Bookshelf.js

 2 years ago
source link: https://devhints.io/bookshelf
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Model

Summary = bookshelf.Model.extend({
  tableName: 'summaries',
  hasTimestamps: true,
  hasTimestamps: ['created_at', 'updated_at'],
})

Associations

Summary = bookshelf.Model.extend({
  book () {
    return this.belongsTo(Book)
  },
  author () {
    return this.hasOne(Author)
  }
  // belongsToMany
  // hasMany
  // hasMany().through()
})
Book.create({ title: '..' }).save()
new Book({ title: '..' }).save()

new Book({ id: 1 }).fetch()

Book.where({ id: 1 }).fetch()
Book.where('favorite_color', 'red').fetch()
Book.where('favorite_color', '<>', 'red').fetch()
Book
  .query((q) => q.orderBy('updated_at')

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK