Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knex-model

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knex-model - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

11

lib/base.js

@@ -16,3 +16,8 @@ 'use strict';

Base.find = function() {
Base.find = function(query) {
// default find all
if(typeof query === 'undefined') {
Array.prototype.push.call(arguments, {});
}
var self = this;

@@ -40,1 +45,5 @@ var knex = this._knex(this._tableName);

};
Base.prototype.toJSON = function() {
return this._meta;
};

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

var KenxModel = {
VERSION: '0.0.1',
VERSION: '0.0.2',
define: define

@@ -21,3 +21,3 @@ };

function define(name, definition) {
function define(name, definition, prototype, classProps) {
if(typeof name !== 'string') {

@@ -33,5 +33,9 @@ definition = name;

};
_.extend(model.prototype, Base.prototype);
_.extend(model, Base, { _tableName: tableName });
// save super class prototype
model.prototype.super = Base.prototype;
_.extend(model.prototype, Base.prototype, prototype);
_.extend(model, Base, classProps,{ _tableName: tableName });
relationBuilder(model, definition);

@@ -70,3 +74,15 @@

}
if(definition.hasOne) {
var hasOne = definition.hasOne;
hasOne = _.isArray(hasOne) ? hasOne : [ hasOne ];
_.each(hasOne, function(item) {
var name = item.name || item.model;
proto.__defineGetter__(name, function() {
var target = momery[item.model];
return new Relation(this, 'hasOne', target, item.key);
});
});
}
}
};

4

lib/relation.js

@@ -46,5 +46,5 @@ 'use strict';

var foreign = this.target;
if(this.type == 'hasMany') {
if(this.type === 'hasMany' || this.type === 'hasOne') {
query[this.keyField] = source.id;
} else if(this.type == 'belongsTo') {
} else if(this.type === 'belongsTo') {
query.id = source._meta[this.keyField];

@@ -51,0 +51,0 @@ }

{
"name": "knex-model",
"version": "0.0.1",
"version": "0.0.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -55,2 +55,2 @@ # knex-model

- [ ] Relation `through`
- [ ] Realtion `hasOne`
- [x] Realtion `hasOne`
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