Socket
Socket
Sign inDemoInstall

objection

Package Overview
Dependencies
Maintainers
2
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objection - npm Package Compare versions

Comparing version 0.5.0-alpha.0 to 0.5.0-alpha.1

lib/relations/BelongsToOneRelation.js

384

lib/model/Model.js
'use strict';
var _desc, _value, _class, _class2, _temp;
var _dec, _dec2, _desc, _value, _class, _class2, _temp;

@@ -80,10 +80,14 @@ Object.defineProperty(exports, "__esModule", {

var _OneToOneRelation = require('../relations/OneToOneRelation');
var _HasOneRelation = require('../relations/HasOneRelation');
var _OneToOneRelation2 = _interopRequireDefault(_OneToOneRelation);
var _HasOneRelation2 = _interopRequireDefault(_HasOneRelation);
var _OneToManyRelation = require('../relations/OneToManyRelation');
var _HasManyRelation = require('../relations/HasManyRelation');
var _OneToManyRelation2 = _interopRequireDefault(_OneToManyRelation);
var _HasManyRelation2 = _interopRequireDefault(_HasManyRelation);
var _BelongsToOneRelation = require('../relations/BelongsToOneRelation');
var _BelongsToOneRelation2 = _interopRequireDefault(_BelongsToOneRelation);
var _ManyToManyRelation = require('../relations/ManyToManyRelation');

@@ -170,3 +174,3 @@

* pets: {
* relation: Model.OneToManyRelation,
* relation: Model.HasManyRelation,
* // The related model. This can be either a Model subclass constructor or an

@@ -197,3 +201,3 @@ * // absolute file path to a module that exports one. We use the file path version

* children: {
* relation: Model.OneToManyRelation,
* relation: Model.HasManyRelation,
* modelClass: Person,

@@ -211,3 +215,3 @@ * join: {

*/
var Model = (_class = (_temp = _class2 = function (_ModelBase) {
var Model = (_dec = (0, _decorators.deprecated)({ removedIn: '0.7.0', useInstead: 'BelongsToOneRelation' }), _dec2 = (0, _decorators.deprecated)({ removedIn: '0.7.0', useInstead: 'HasManyRelation' }), (_class = (_temp = _class2 = function (_ModelBase) {
(0, _inherits3.default)(Model, _ModelBase);

@@ -247,76 +251,2 @@

*/
/**
* @private
*/
/**
* Properties that should be saved to database as JSON strings.
*
* The properties listed here are serialized to JSON strings upon insertion to the database
* and parsed back to objects when models are read from the database. Combined with the
* postgresql's json or jsonb data type, this is a powerful way of representing documents
* as single database rows.
*
* If this property is left unset all properties declared as objects or arrays in the
* `jsonSchema` are implicitly added to this list.
*
* Example:
*
* ```js
* Person.jsonAttributes = ['address'];
*
* var jennifer = Person.fromJson({
* name: 'Jennifer',
* address: {
* address: 'Someroad 10',
* zipCode: '1234',
* city: 'Los Angeles'
* }
* });
*
* var dbRow = jennifer.$toDatabaseJson();
* console.log(dbRow);
* // --> {name: 'Jennifer', address: '{"address":"Someroad 10","zipCode":"1234","city":"Los Angeles"}'}
* ```
*
* @type {Array.<string>}
*/
/**
* Name of the property used to store a reference to a `uidProp`.
*
* Defaults to '#ref'.
*
* @type {string}
*/
/**
* Name of the primary key column in the database table.
*
* Composite id can be specified by giving an array of column names.
*
* Defaults to 'id'.
*
* @type {string|Array.<string>}
*/
/**
* may-to-many relation type.
*
* @type {ManyToManyRelation}
*/
/**
* one-to-many relation type.
*
* @type {OneToOneRelation}
*/
/**
* QueryBuilder subclass to use in `query()` or `$query()` methods.
*
* This constructor is used whenever a query builder is created using `query()` or `$query()` methods.
* You can override this to use your own `QueryBuilder` subclass.
*/
value: function $id() {

@@ -336,94 +266,2 @@ if (arguments.length > 0) {

/**
* @private
*/
/**
* This property defines the relations to other models.
*
* Relations to other models can be defined by setting this property. The best way to explain how to
* do this is by example:
*
* ```js
* Person.relationMappings = {
* pets: {
* relation: Model.OneToManyRelation,
* modelClass: Animal,
* join: {
* from: 'Person.id',
* to: 'Animal.ownerId'
* }
* },
*
* father: {
* relation: Model.OneToOneRelation,
* modelClass: Person,
* join: {
* from: 'Person.fatherId',
* to: 'Person.id'
* }
* },
*
* movies: {
* relation: Model.ManyToManyRelation,
* modelClass: Movie,
* join: {
* from: 'Person.id',
* through: {
* from: 'Person_Movie.actorId',
* to: 'Person_Movie.movieId'
* },
* to: 'Movie.id'
* }
* }
* };
* ```
*
* relationMappings is an object whose keys are relation names and values define the relation. The
* `join` property in addition to the relation type define how the models are related to one another.
* The `from` and `to` properties of the `join` object define the database columns through which the
* models are associated. Note that neither of these columns need to be primary keys. They can be any
* columns!. In the case of ManyToManyRelation also the join table needs to be defined. This is
* done using the `through` object.
*
* The `modelClass` passed to the relation mappings is the class of the related model. It can be either
* a Model subclass constructor or an absolute path to a module that exports one. Using file paths
* is a handy way to prevent require loops.
*
* @type {Object.<string, RelationMapping>}
*/
/**
* Regular expression for parsing a reference to a property.
*
* @type {RegExp}
*/
/**
* Name of the property used to store a temporary non-db identifier for the model.
*
* Defaults to '#id'.
*
* @type {string}
*/
/**
* Name of the database table of this model.
*
* @type {string}
*/
/**
* one-to-many relation type.
*
* @type {OneToManyRelation}
*/
/**
* QueryBuilder subclass to use in `$relatedQuery()` method.
*
* This constructor is used whenever a query builder is created using the `$relatedQuery()` method.
* You can override this to use your own `QueryBuilder` subclass.
*/
}, {

@@ -1635,5 +1473,201 @@ key: '$knex',

}
}, {
key: 'OneToOneRelation',
/**
* one-to-many relation type.
*
* @type {OneToOneRelation}
*/
/**
* one-to-one relation type.
*
* @type {BelongsToOneRelation}
*/
/**
* QueryBuilder subclass to use in `$relatedQuery()` method.
*
* This constructor is used whenever a query builder is created using the `$relatedQuery()` method.
* You can override this to use your own `QueryBuilder` subclass.
*/
get: function get() {
return _BelongsToOneRelation2.default;
}
/**
* one-to-many relation type.
*
* @type {OneToManyRelation}
*/
/**
* one-to-many relation type.
*
* @type {HasManyRelation}
*/
/**
* one-to-one relation type.
*
* @type {HasOneRelation}
*/
/**
* QueryBuilder subclass to use in `query()` or `$query()` methods.
*
* This constructor is used whenever a query builder is created using `query()` or `$query()` methods.
* You can override this to use your own `QueryBuilder` subclass.
*/
}, {
key: 'OneToManyRelation',
get: function get() {
return _HasManyRelation2.default;
}
/**
* may-to-many relation type.
*
* @type {ManyToManyRelation}
*/
/**
* Name of the database table of this model.
*
* @type {string}
*/
/**
* Name of the primary key column in the database table.
*
* Composite id can be specified by giving an array of column names.
*
* Defaults to 'id'.
*
* @type {string|Array.<string>}
*/
/**
* Name of the property used to store a temporary non-db identifier for the model.
*
* Defaults to '#id'.
*
* @type {string}
*/
/**
* Name of the property used to store a reference to a `uidProp`.
*
* Defaults to '#ref'.
*
* @type {string}
*/
/**
* Regular expression for parsing a reference to a property.
*
* @type {RegExp}
*/
/**
* Properties that should be saved to database as JSON strings.
*
* The properties listed here are serialized to JSON strings upon insertion to the database
* and parsed back to objects when models are read from the database. Combined with the
* postgresql's json or jsonb data type, this is a powerful way of representing documents
* as single database rows.
*
* If this property is left unset all properties declared as objects or arrays in the
* `jsonSchema` are implicitly added to this list.
*
* Example:
*
* ```js
* Person.jsonAttributes = ['address'];
*
* var jennifer = Person.fromJson({
* name: 'Jennifer',
* address: {
* address: 'Someroad 10',
* zipCode: '1234',
* city: 'Los Angeles'
* }
* });
*
* var dbRow = jennifer.$toDatabaseJson();
* console.log(dbRow);
* // --> {name: 'Jennifer', address: '{"address":"Someroad 10","zipCode":"1234","city":"Los Angeles"}'}
* ```
*
* @type {Array.<string>}
*/
/**
* This property defines the relations to other models.
*
* Relations to other models can be defined by setting this property. The best way to explain how to
* do this is by example:
*
* ```js
* Person.relationMappings = {
* pets: {
* relation: Model.HasManyRelation,
* modelClass: Animal,
* join: {
* from: 'Person.id',
* to: 'Animal.ownerId'
* }
* },
*
* father: {
* relation: Model.BelongsToOneRelation,
* modelClass: Person,
* join: {
* from: 'Person.fatherId',
* to: 'Person.id'
* }
* },
*
* movies: {
* relation: Model.ManyToManyRelation,
* modelClass: Movie,
* join: {
* from: 'Person.id',
* through: {
* from: 'Person_Movie.actorId',
* to: 'Person_Movie.movieId'
* },
* to: 'Movie.id'
* }
* }
* };
* ```
*
* relationMappings is an object whose keys are relation names and values define the relation. The
* `join` property in addition to the relation type define how the models are related to one another.
* The `from` and `to` properties of the `join` object define the database columns through which the
* models are associated. Note that neither of these columns need to be primary keys. They can be any
* columns!. In the case of ManyToManyRelation also the join table needs to be defined. This is
* done using the `through` object.
*
* The `modelClass` passed to the relation mappings is the class of the related model. It can be either
* a Model subclass constructor or an absolute path to a module that exports one. Using file paths
* is a handy way to prevent require loops.
*
* @type {Object.<string, RelationMapping>}
*/
/**
* @private
*/
/**
* @private
*/
}]);
return Model;
}(_ModelBase3.default), _class2.QueryBuilder = _QueryBuilder2.default, _class2.RelatedQueryBuilder = _QueryBuilder2.default, _class2.OneToOneRelation = _OneToOneRelation2.default, _class2.OneToManyRelation = _OneToManyRelation2.default, _class2.ManyToManyRelation = _ManyToManyRelation2.default, _class2.tableName = null, _class2.idColumn = 'id', _class2.uidProp = '#id', _class2.uidRefProp = '#ref', _class2.propRefRegex = /#ref{([^\.]+)\.([^}]+)}/g, _class2.jsonAttributes = null, _class2.relationMappings = null, _class2.$$knex = null, _class2.$$relations = null, _temp), (_applyDecoratedDescriptor(_class, 'getIdProperty', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getIdProperty'), _class), _applyDecoratedDescriptor(_class, 'getFullIdColumn', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getFullIdColumn'), _class)), _class);
}(_ModelBase3.default), _class2.QueryBuilder = _QueryBuilder2.default, _class2.RelatedQueryBuilder = _QueryBuilder2.default, _class2.HasOneRelation = _HasOneRelation2.default, _class2.BelongsToOneRelation = _BelongsToOneRelation2.default, _class2.HasManyRelation = _HasManyRelation2.default, _class2.ManyToManyRelation = _ManyToManyRelation2.default, _class2.tableName = null, _class2.idColumn = 'id', _class2.uidProp = '#id', _class2.uidRefProp = '#ref', _class2.propRefRegex = /#ref{([^\.]+)\.([^}]+)}/g, _class2.jsonAttributes = null, _class2.relationMappings = null, _class2.$$knex = null, _class2.$$relations = null, _temp), (_applyDecoratedDescriptor(_class, 'OneToOneRelation', [_dec], (0, _getOwnPropertyDescriptor2.default)(_class, 'OneToOneRelation'), _class), _applyDecoratedDescriptor(_class, 'OneToManyRelation', [_dec2], (0, _getOwnPropertyDescriptor2.default)(_class, 'OneToManyRelation'), _class), _applyDecoratedDescriptor(_class, 'getIdProperty', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getIdProperty'), _class), _applyDecoratedDescriptor(_class, 'getFullIdColumn', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getFullIdColumn'), _class)), _class));

@@ -1640,0 +1674,0 @@ /**

@@ -6,3 +6,3 @@ 'use strict';

});
exports.Promise = exports.transaction = exports.ManyToManyRelation = exports.OneToManyRelation = exports.OneToOneRelation = exports.Relation = exports.ValidationError = exports.RelationExpression = exports.QueryBuilderBase = exports.QueryBuilder = exports.Model = exports.ModelBase = undefined;
exports.Promise = exports.transaction = exports.ManyToManyRelation = exports.BelongsToOneRelation = exports.HasManyRelation = exports.HasOneRelation = exports.Relation = exports.ValidationError = exports.RelationExpression = exports.QueryBuilderBase = exports.QueryBuilder = exports.Model = exports.ModelBase = undefined;

@@ -37,10 +37,14 @@ var _ModelBase = require('./model/ModelBase');

var _OneToOneRelation = require('./relations/OneToOneRelation');
var _HasOneRelation = require('./relations/HasOneRelation');
var _OneToOneRelation2 = _interopRequireDefault(_OneToOneRelation);
var _HasOneRelation2 = _interopRequireDefault(_HasOneRelation);
var _OneToManyRelation = require('./relations/OneToManyRelation');
var _HasManyRelation = require('./relations/HasManyRelation');
var _OneToManyRelation2 = _interopRequireDefault(_OneToManyRelation);
var _HasManyRelation2 = _interopRequireDefault(_HasManyRelation);
var _BelongsToOneRelation = require('./relations/BelongsToOneRelation');
var _BelongsToOneRelation2 = _interopRequireDefault(_BelongsToOneRelation);
var _ManyToManyRelation = require('./relations/ManyToManyRelation');

@@ -67,6 +71,21 @@

exports.Relation = _Relation2.default;
exports.OneToOneRelation = _OneToOneRelation2.default;
exports.OneToManyRelation = _OneToManyRelation2.default;
exports.HasOneRelation = _HasOneRelation2.default;
exports.HasManyRelation = _HasManyRelation2.default;
exports.BelongsToOneRelation = _BelongsToOneRelation2.default;
exports.ManyToManyRelation = _ManyToManyRelation2.default;
exports.transaction = _transaction2.default;
exports.Promise = _bluebird2.default;
exports.Promise = _bluebird2.default;
Object.defineProperty(module.exports, "OneToOneRelation", {
get: function get() {
console.warn('OneToOneRelation is deprecated and will be removed in version 0.7.0. Use BelongsToOneRelation instead. Simply replace OneToOneRelation with BelongsToOneRelation.');
return _BelongsToOneRelation2.default;
}
});
Object.defineProperty(module.exports, "OneToManyRelation", {
get: function get() {
console.warn('OneToManyRelation is deprecated and will be removed in version 0.7.0. Use HasManyRelation instead. Simply replace OneToManyRelation with HasManyRelation.');
return _HasManyRelation2.default;
}
});

@@ -36,9 +36,9 @@ 'use strict';

var _OneToManyRelation = require('../relations/OneToManyRelation');
var _HasManyRelation = require('../relations/HasManyRelation');
var _OneToManyRelation2 = _interopRequireDefault(_OneToManyRelation);
var _HasManyRelation2 = _interopRequireDefault(_HasManyRelation);
var _OneToOneRelation = require('../relations/OneToOneRelation');
var _BelongsToOneRelation = require('../relations/BelongsToOneRelation');
var _OneToOneRelation2 = _interopRequireDefault(_OneToOneRelation);
var _BelongsToOneRelation2 = _interopRequireDefault(_BelongsToOneRelation);

@@ -444,3 +444,3 @@ var _ValidationError = require('../ValidationError');

if (rel instanceof _OneToManyRelation2.default) {
if (rel instanceof _HasManyRelation2.default) {

@@ -458,3 +458,3 @@ node.needs.push(new Dependency(parentNode, function (model) {

}));
} else if (rel instanceof _OneToOneRelation2.default) {
} else if (rel instanceof _BelongsToOneRelation2.default) {

@@ -461,0 +461,0 @@ node.isNeededBy.push(new Dependency(parentNode, function (model) {

@@ -132,3 +132,3 @@ 'use strict';

* @property {Relation} relation
* A relation constructor. You can use one of Model.OneToOneRelation, Model.OneToManyRelation and
* A relation constructor. You can use one of Model.BelongsToOneRelation, Model.HasOneRelation, Model.HasManyRelation and
* Model.ManyToManyRelation or even write your own relation type by subclassing {@link Relation}.

@@ -448,7 +448,4 @@ *

var idProperty = modelClass.getIdProperty();
if (!_lodash2.default.isArray(idProperty)) {
idProperty = [idProperty];
}
return _lodash2.default.sortByAll(models, idProperty);
return _lodash2.default.sortByAll(models, _lodash2.default.isArray(idProperty) ? idProperty : [idProperty]);
}

@@ -513,5 +510,3 @@

/* istanbul ignore next */
/**
* @abstract
* @param {QueryBuilder} builder

@@ -524,2 +519,29 @@ * @param {Array.<Model>} owners

value: function find(builder, owners) {
var _this3 = this;
builder.onBuild(function (builder) {
var ids = (0, _lodash2.default)(owners).map(function (owner) {
return owner.$values(_this3.ownerProp);
}).unique(function (id) {
return id.join();
}).value();
_this3.findQuery(builder, ids);
});
builder.runAfterModelCreate(function (related) {
_this3.createRelationProp(owners, related);
return related;
});
}
/* istanbul ignore next */
/**
* @abstract
* @protected
*/
}, {
key: 'createRelationProp',
value: function createRelationProp(owners, related) {
this.throwError('not implemented');

@@ -551,6 +573,6 @@ }

value: function update(builder, owner, _update) {
var _this3 = this;
var _this4 = this;
builder.onBuild(function (builder) {
_this3.findQuery(builder, [owner.$values(_this3.ownerProp)]);
_this4.findQuery(builder, [owner.$values(_this4.ownerProp)]);
builder.$$update(_update);

@@ -580,6 +602,6 @@ });

value: function _delete(builder, owner) {
var _this4 = this;
var _this5 = this;
builder.onBuild(function (builder) {
_this4.findQuery(builder, [owner.$values(_this4.ownerProp)]);
_this5.findQuery(builder, [owner.$values(_this5.ownerProp)]);
builder.$$delete();

@@ -623,3 +645,3 @@ });

value: function propertyName(columns, modelClass) {
var _this5 = this;
var _this6 = this;

@@ -630,3 +652,3 @@ return _lodash2.default.map(columns, function (column) {

if (!propertyName) {
throw new Error(modelClass.name + '.$parseDatabaseJson probably transforms the value of the column ' + column + '.' + ' This is a no-no because ' + column + ' is needed in the relation ' + _this5.ownerModelClass.tableName + '.' + _this5.name);
throw new Error(modelClass.name + '.$parseDatabaseJson probably transforms the value of the column ' + column + '.' + ' This is a no-no because ' + column + ' is needed in the relation ' + _this6.ownerModelClass.tableName + '.' + _this6.name);
}

@@ -700,3 +722,3 @@

value: function normalizeId(ids, compositeLength) {
var _this6 = this;
var _this7 = this;

@@ -732,3 +754,3 @@ var isComposite = compositeLength > 1;

if (id.length !== compositeLength) {
_this6.throwError('Id ' + id + ' has invalid length. Expected ' + compositeLength);
_this7.throwError('Id ' + id + ' has invalid length. Expected ' + compositeLength);
}

@@ -735,0 +757,0 @@ });

@@ -17,2 +17,6 @@ 'use strict';

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -65,9 +69,21 @@

return function (target, property, descriptor) {
var impl = descriptor.value;
var message = property + ' is deprecated and will be removed in version ' + opt.removedIn + '. Use ' + opt.useInstead + ' instead.';
descriptor.value = function () {
console.warn('method ' + property + ' is deprecated and will be removed in version ' + opt.removedIn + '. Use ' + opt.useInstead + ' instead.');
return impl.apply(this, arguments);
};
var value = descriptor.value;
var getter = descriptor.get;
if (_lodash2.default.isFunction(value)) {
descriptor.value = function () {
console.warn(message);
return value.apply(this, arguments);
};
}
if (_lodash2.default.isFunction(getter)) {
descriptor.get = function () {
console.warn(message);
return getter.apply(this, arguments);
};
}
};
}
{
"name": "objection",
"version": "0.5.0-alpha.0",
"version": "0.5.0-alpha.1",
"description": "An SQL-friendly ORM for Node.js",

@@ -12,3 +12,3 @@ "main": "lib/objection.js",

"test-bail": "mocha --slow 10 --timeout 5000 --reporter spec --recursive tests --bail",
"coveralls": "cat ./test-coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"coveralls": "cat ./testCoverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"prepublish": "npm run build"

@@ -15,0 +15,0 @@ },

@@ -8,7 +8,8 @@ import _ from 'lodash';

import EagerFetcher from '../queryBuilder/EagerFetcher';
import {memoize} from '../utils/decorators';
import {memoize, deprecated} from '../utils/decorators';
import Relation from '../relations/Relation';
import OneToOneRelation from '../relations/OneToOneRelation';
import OneToManyRelation from '../relations/OneToManyRelation';
import HasOneRelation from '../relations/HasOneRelation';
import HasManyRelation from '../relations/HasManyRelation';
import BelongsToOneRelation from '../relations/BelongsToOneRelation';
import ManyToManyRelation from '../relations/ManyToManyRelation';

@@ -62,3 +63,3 @@

* pets: {
* relation: Model.OneToManyRelation,
* relation: Model.HasManyRelation,
* // The related model. This can be either a Model subclass constructor or an

@@ -89,3 +90,3 @@ * // absolute file path to a module that exports one. We use the file path version

* children: {
* relation: Model.OneToManyRelation,
* relation: Model.HasManyRelation,
* modelClass: Person,

@@ -122,7 +123,31 @@ * join: {

/**
* one-to-one relation type.
*
* @type {HasOneRelation}
*/
static HasOneRelation = HasOneRelation;
/**
* one-to-one relation type.
*
* @type {BelongsToOneRelation}
*/
static BelongsToOneRelation = BelongsToOneRelation;
/**
* one-to-many relation type.
*
* @type {HasManyRelation}
*/
static HasManyRelation = HasManyRelation;
/**
* one-to-many relation type.
*
* @type {OneToOneRelation}
*/
static OneToOneRelation = OneToOneRelation;
@deprecated({removedIn: '0.7.0', useInstead: 'BelongsToOneRelation'})
static get OneToOneRelation() {
return BelongsToOneRelation;
}

@@ -134,3 +159,6 @@ /**

*/
static OneToManyRelation = OneToManyRelation;
@deprecated({removedIn: '0.7.0', useInstead: 'HasManyRelation'})
static get OneToManyRelation() {
return HasManyRelation;
}

@@ -230,3 +258,3 @@ /**

* pets: {
* relation: Model.OneToManyRelation,
* relation: Model.HasManyRelation,
* modelClass: Animal,

@@ -240,3 +268,3 @@ * join: {

* father: {
* relation: Model.OneToOneRelation,
* relation: Model.BelongsToOneRelation,
* modelClass: Person,

@@ -243,0 +271,0 @@ * join: {

@@ -9,4 +9,5 @@ import ModelBase from './model/ModelBase';

import Relation from './relations/Relation';
import OneToOneRelation from './relations/OneToOneRelation';
import OneToManyRelation from './relations/OneToManyRelation';
import HasOneRelation from './relations/HasOneRelation';
import HasManyRelation from './relations/HasManyRelation';
import BelongsToOneRelation from './relations/BelongsToOneRelation';
import ManyToManyRelation from './relations/ManyToManyRelation';

@@ -25,4 +26,5 @@

Relation,
OneToOneRelation,
OneToManyRelation,
HasOneRelation,
HasManyRelation,
BelongsToOneRelation,
ManyToManyRelation,

@@ -32,1 +34,15 @@ transaction,

};
Object.defineProperty(module.exports, "OneToOneRelation", {
get: function () {
console.warn(`OneToOneRelation is deprecated and will be removed in version 0.7.0. Use BelongsToOneRelation instead. Simply replace OneToOneRelation with BelongsToOneRelation.`);
return BelongsToOneRelation;
}
});
Object.defineProperty(module.exports, "OneToManyRelation", {
get: function () {
console.warn(`OneToManyRelation is deprecated and will be removed in version 0.7.0. Use HasManyRelation instead. Simply replace OneToManyRelation with HasManyRelation.`);
return HasManyRelation;
}
});

@@ -5,4 +5,4 @@ import _ from 'lodash';

import ManyToManyRelation from '../relations/ManyToManyRelation';
import OneToManyRelation from '../relations/OneToManyRelation';
import OneToOneRelation from '../relations/OneToOneRelation';
import HasManyRelation from '../relations/HasManyRelation';
import BelongsToOneRelation from '../relations/BelongsToOneRelation';
import ValidationError from '../ValidationError';

@@ -347,3 +347,3 @@ let Model;

if (rel instanceof OneToManyRelation) {
if (rel instanceof HasManyRelation) {

@@ -362,3 +362,3 @@ node.needs.push(new Dependency(parentNode, function (model) {

} else if (rel instanceof OneToOneRelation) {
} else if (rel instanceof BelongsToOneRelation) {

@@ -365,0 +365,0 @@ node.isNeededBy.push(new Dependency(parentNode, function (model) {

@@ -48,8 +48,8 @@ import _ from 'lodash';

this.clearHooks();
this.clearCustomImpl();
this.internalContext().runBefore = [];
this.internalContext().runAfter = [];
this.internalContext().onBuild = [];
this.clearHooks();
this.clearCustomImpl();
}

@@ -127,3 +127,3 @@

/**
* Should call this for all other queries a QueryBuilder starts with the "parent" query as parameter.
* Should call this for all other queries a QueryBuilder starts.
*

@@ -130,0 +130,0 @@ * For internal use only.

@@ -69,3 +69,3 @@ import _ from 'lodash';

* @property {Relation} relation
* A relation constructor. You can use one of Model.OneToOneRelation, Model.OneToManyRelation and
* A relation constructor. You can use one of Model.BelongsToOneRelation, Model.HasOneRelation, Model.HasManyRelation and
* Model.ManyToManyRelation or even write your own relation type by subclassing {@link Relation}.

@@ -360,7 +360,4 @@ *

let idProperty = modelClass.getIdProperty();
if (!_.isArray(idProperty)) {
idProperty = [idProperty];
}
return _.sortByAll(models, idProperty);
return _.sortByAll(models, _.isArray(idProperty) ? idProperty : [idProperty]);
}

@@ -417,5 +414,3 @@

/* istanbul ignore next */
/**
* @abstract
* @param {QueryBuilder} builder

@@ -425,2 +420,23 @@ * @param {Array.<Model>} owners

find(builder, owners) {
builder.onBuild(builder => {
let ids = _(owners)
.map(owner => owner.$values(this.ownerProp))
.unique(id => id.join())
.value();
this.findQuery(builder, ids);
});
builder.runAfterModelCreate(related => {
this.createRelationProp(owners, related);
return related;
});
}
/* istanbul ignore next */
/**
* @abstract
* @protected
*/
createRelationProp(owners, related) {
this.throwError('not implemented');

@@ -427,0 +443,0 @@ }

@@ -0,1 +1,3 @@

import _ from 'lodash';
/**

@@ -46,9 +48,21 @@ * @ignore

return function (target, property, descriptor) {
const impl = descriptor.value;
const message = `${property} is deprecated and will be removed in version ${opt.removedIn}. Use ${opt.useInstead} instead.`;
descriptor.value = function () {
console.warn(`method ${property} is deprecated and will be removed in version ${opt.removedIn}. Use ${opt.useInstead} instead.`);
return impl.apply(this, arguments);
};
const value = descriptor.value;
const getter = descriptor.get;
if (_.isFunction(value)) {
descriptor.value = function () {
console.warn(message);
return value.apply(this, arguments);
};
}
if (_.isFunction(getter)) {
descriptor.get = function () {
console.warn(message);
return getter.apply(this, arguments);
};
}
};
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc