Skip to content
Merged
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
9 changes: 3 additions & 6 deletions lib/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,10 @@ Table.prototype.addColumn = function(col, options) {
};

Table.prototype.hasColumn = function(col) {
col = this.createColumn(col);

var cols = this.columns.filter(function(column) {
return column.property === col.property || column.name === col.name;
var columnName = col instanceof Column ? col.name : col;
return this.columns.some(function(column) {
return column.property === columnName || column.name === columnName;
});

return cols.length > 0;
};

Table.prototype.getColumn =
Expand Down
13 changes: 13 additions & 0 deletions test/table-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ test('hasColumn', function() {
assert.equal(table.hasColumn('baz'), true);
});

test('hasColumn with user-defined column property', function() {
var table = Table.define({
name: 'blah',
columns: [{
name: 'id',
property: 'theId'
}, {name: 'foo'}]
});

assert.equal(table.hasColumn('id'), true);
assert.equal(table.hasColumn('theId'), true);
});

test('the column "from" does not overwrite the from method', function() {
var table = Table.define({ name: 'foo', columns: [] });
table.addColumn('from');
Expand Down