Skip to content

Commit

Permalink
Nest batch-created record values under "fields" (#106)
Browse files Browse the repository at this point in the history
Before:

    await myTable.create([
      {foo: 'boo'},
      {foo: 'bar'},
    ])

After:

    await myTable.create([
      {fields: {foo: 'boo'}},
      {fields: {foo: 'bar'}},
    ])

As a side-effect of this change, we stopped calling
`Array.prototype.map`, which may not be available in older browsers.
  • Loading branch information
Evan Hahn authored Apr 30, 2019
1 parent 010eb64 commit 0421165
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
6 changes: 1 addition & 5 deletions lib/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ var Table = Class.extend({
}
var requestData;
if (isCreatingMultipleRecords) {
requestData = {
records: recordsData.map(function (fields) {
return {fields: fields};
}),
};
requestData = {records: recordsData};
} else {
requestData = {fields: recordsData};
}
Expand Down
16 changes: 9 additions & 7 deletions test/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ describe('record creation', function () {
return airtable
.base('app123')
.table('Table')
.create([{foo: 'boo'}])
.create([{
fields: {foo: 'boo'}
}])
.then(function (createdRecords) {
expect(createdRecords).toHaveLength(1);
expect(createdRecords[0].id).toBe('rec0');
Expand All @@ -79,8 +81,8 @@ describe('record creation', function () {
.base('app123')
.table('Table')
.create([
{foo: 'boo'},
{bar: 'yar'},
{fields: {foo: 'boo'}},
{fields: {bar: 'yar'}},
])
.then(function (createdRecords) {
expect(createdRecords).toHaveLength(2);
Expand All @@ -96,8 +98,8 @@ describe('record creation', function () {
.base('app123')
.table('Table')
.create([
{foo: 'boo'},
{bar: 'yar'},
{fields: {foo: 'boo'}},
{fields: {bar: 'yar'}},
], function (err, createdRecords) {
expect(err).toBeNull();
expect(createdRecords).toHaveLength(2);
Expand All @@ -114,8 +116,8 @@ describe('record creation', function () {
.base('app123')
.table('Table')
.create([
{foo: 'boo'},
{bar: 'yar'},
{fields: {foo: 'boo'}},
{fields: {bar: 'yar'}},
], {typecast: true})
.then(function (createdRecords) {
expect(createdRecords).toHaveLength(2);
Expand Down

0 comments on commit 0421165

Please sign in to comment.