Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bookshelf/bookshelf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: zubeio/bookshelf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 10 commits
  • 3 files changed
  • 2 contributors

Commits on Aug 30, 2015

  1. Return * on insert

    jendewalt committed Aug 30, 2015
    Copy the full SHA
    d1bd476 View commit details
  2. Copy the full SHA
    9672409 View commit details
  3. Use lodash

    jendewalt committed Aug 30, 2015
    Copy the full SHA
    54e2a83 View commit details
  4. Copy the full SHA
    418d0b0 View commit details
  5. Copy the full SHA
    fbff49b View commit details
  6. Sm fix

    jendewalt committed Aug 30, 2015
    Copy the full SHA
    40c18ad View commit details

Commits on Sep 4, 2015

  1. Copy the full SHA
    0c3dce3 View commit details
  2. Copy the full SHA
    9998e7f View commit details

Commits on Sep 6, 2015

  1. Copy the full SHA
    b02321c View commit details
  2. Copy the full SHA
    dee20cb View commit details
Showing with 83 additions and 67 deletions.
  1. +20 −13 lib/base/model.js
  2. +57 −51 lib/model.js
  3. +6 −3 lib/sync.js
33 changes: 20 additions & 13 deletions lib/base/model.js
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ ModelBase.prototype.initialize = function () {};

/**
* @name ModelBase#tableName
* @member {string}
* @member {string}
* @description
*
* A required property for any database usage, The
@@ -142,7 +142,7 @@ ModelBase.prototype.set = function (key, val, options) {
*
* var modelA = new bookshelf.Model();
* modelA.isNew(); // true
*
*
* var modelB = new bookshelf.Model({id: 1});
* modelB.isNew(); // false
*/
@@ -185,7 +185,14 @@ ModelBase.prototype.serialize = function (options) {
var relations = this.relations;
for (var key in relations) {
var relation = relations[key];
attrs[key] = relation.toJSON ? relation.toJSON(options) : relation;
// Zube addition so relations that are not present are null instead of {}
if (relation.toJSON) {
var relationAttrs = relation.toJSON(options);
if (_.isEmpty(relationAttrs) && !_.isArray(relationAttrs)) relationAttrs = null;
attrs[key] = relationAttrs;
} else {
attrs[key] = relation;
}
}
if (options && options.omitPivot) return attrs;
if (this.pivot) {
@@ -430,7 +437,7 @@ ModelBase.prototype.timestamp = function (options) {
* Model#destroy destroy}. If an attribute is passed, returns true only if that
* specific attribute has changed.
*
* @param {string=} attribute
* @param {string=} attribute
* @returns {bool}
* `true` if any attribute has changed. Or, if `attribute` was specified, true
* if it has changed.
@@ -534,32 +541,32 @@ _.each(modelMethods, function (method) {
* var checkit = require('checkit');
* var Promise = require('bluebird');
* var bcrypt = Promise.promisifyAll(require('bcrypt'));
*
*
* var Customer = bookshelf.Model.extend({
*
*
* initialize: function() {
* this.on('saving', this.validateSave);
* },
*
*
* validateSave: function() {
* return checkit(rules).run(this.attributes);
* },
*
*
* account: function() {
* return this.belongsTo(Account);
* },
*
*
* }, {
*
*
* login: Promise.method(function(email, password) {
* if (!email || !password) throw new Error('Email and password are both required');
* return new this({email: email.toLowerCase().trim()}).fetch({require: true}).tap(function(customer) {
* return bcrypt.compareAsync(customer.get('password'), password);
* });
* })
*
*
* });
*
*
* Customer.login(email, password)
* .then(function(customer) {
* res.json(customer.omit('password'));
@@ -593,4 +600,4 @@ _.each(modelMethods, function (method) {
*/
ModelBase.extend = require('../extend');

module.exports = ModelBase;
module.exports = ModelBase;
Loading