How to use the bookshelf.Model function in bookshelf

To help you get started, we’ve selected a few bookshelf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leviwheatcroft / concierge / lib / db.js View on Github external
.then(function() {
    // inject model into promise chain as return value
    return bookshelf.Model.extend({
      tableName: 'genres'
    });
  })
  .catch(function(e) {
github cobyism / ghost-on-heroku / core / shared / models / models.js View on Github external
(function () {
    "use strict";

    // We should just be able to require bookshelf and have it reference
    // the `Knex` instance bootstraped at the app initialization.
    var Bookshelf = require('bookshelf'),
        Showdown = require('showdown'),
        converter = new Showdown.converter(),

        Post,
        Posts,
        User,
        Setting,
        Settings;

    Post = Bookshelf.Model.extend({

        tableName: 'posts',

        hasTimestamps: true,

        initialize: function () {
            this.on('creating', this.creating, this);
            this.on('saving', this.saving, this);
        },

        saving: function () {
            if (!this.get('title')) {
                throw new Error('Post title cannot be blank');
            }
            this.set('content_html', converter.makeHtml(this.get('content')));
github leviwheatcroft / concierge / lib / db.js View on Github external
.then(function() {
    var Genres;
    Genres = bookshelf.Model.extend({
      tableName: 'genres'
    });
    return Genres.count()
    .then(function(count) {
      if (count > 0) {
        return Promise.resolve();
      }
      log.info('populating Genres from tmdb');
      tmdb = tmdb(config.apiKey);
      console.log(_.isFunction(tmdb.genreList));
      console.log(_.keys(tmdb));
      tmdb.genreList(function(genres) {
        console.log(genres);
        throw 'die';
      });
      /*
github cobyism / ghost-on-heroku / core / shared / models / models.js View on Github external
return this.set('slug', this.get('title').replace(/\:/g, '').replace(/\s/g, '-').toLowerCase());
        },

        user: function () {
            return this.belongsTo(User, 'created_by');
        }

    });

    Posts = Bookshelf.Collection.extend({

        model: Post

    });

    User = Bookshelf.Model.extend({
        tableName: 'users',
        hasTimestamps: true,
        posts: function () {
            return this.hasMany(Posts, 'created_by');
        }
    });

    Setting = Bookshelf.Model.extend({
        tableName: 'settings',
        hasTimestamps: true
    });

    Settings = Bookshelf.Collection.extend({
        model: Setting
    });