Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#39: added failing tests for when primaryKey set to false #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions test/foreignKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@ var ForeignKeys = require('../lib/waterline-schema/foreignKeys'),

describe('ForeignKeys', function() {

describe('ignore attributes with primaryKey set to false', function() {
var collections = {};

before(function() {
collections.foo = {
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true,
unique: true
},
count: {
type: 'integer',
primaryKey: false
}
}
};

collections.bar = {
attributes: {
foo: { model: 'foo' }
}
};
});

it('should only use the column with primaryKey set to true as foreignKey', function() {
var obj = new ForeignKeys(collections);
assert(obj.bar.attributes.foo);
assert(obj.bar.attributes.foo.on === 'id');
});
});

describe('with automatic column names', function() {
var collections = {};

Expand Down
62 changes: 62 additions & 0 deletions test/joinTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,68 @@ var JoinTables = require('../lib/waterline-schema/joinTables'),

describe('JoinTables', function() {

describe('ignore attributes with primaryKey set to false', function() {
var collections = {};

before(function() {

collections.foo = {
tableName: 'foo',
connection: 'bar',
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true,
unique: true
},
count: {
type: 'integer',
primaryKey: false
},
bars: {
collection: 'bar',
via: 'foos',
dominant: true
}
}
};

collections.bar = {
tableName: 'bar',
connection: 'bar',
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true,
unique: true
},
size: {
type: 'integer',
primaryKey: false
},
foos: {
collection: 'foo',
via: 'bars'
}
}
};
});

it('should only use columns with primaryKey set to true for the junction table', function() {
var obj = new JoinTables(collections);
assert(obj.bar_foos__foo_bars);
assert(obj.bar_foos__foo_bars.attributes);

assert(obj.bar_foos__foo_bars.attributes.foo_bars);
assert(obj.bar_foos__foo_bars.attributes.foo_bars.on === 'id');

assert(obj.bar_foos__foo_bars.attributes.bar_foos);
assert(obj.bar_foos__foo_bars.attributes.bar_foos.on === 'id');
});
});

describe('auto mapping of foreign keys', function() {
var collections = {};

Expand Down