How to use the bookshelf.Collection 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 cobyism / ghost-on-heroku / core / shared / models / models.js View on Github external
});

    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
    });

    module.exports = {
        Post: Post,
        Posts: Posts,
        User: User,
        Setting: Setting,
        Settings: Settings
    };
}());
github cobyism / ghost-on-heroku / core / shared / models / models.js View on Github external
if (!this.get('slug')) {
                this.generateSlug();
            }
        },

        generateSlug: function () {
            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