Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Feb 22, 2017
2 parents b64ac95 + 00aac86 commit 8357c11
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
##### 3.0.0-rc.9 - 22 February 2017

###### Bug fixes
- `Schema#pick` no longer incorrectly infers values for objects and arrays

##### 3.0.0-rc.8 - 21 February 2017

###### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "js-data",
"description": "Robust, framework-agnostic in-memory data store.",
"version": "3.0.0-rc.8",
"version": "3.0.0-rc.9",
"homepage": "http://www.js-data.io",
"repository": {
"type": "git",
Expand Down
5 changes: 3 additions & 2 deletions src/Schema.js
Expand Up @@ -1183,8 +1183,10 @@ export default Component.extend({
* @returns {*} The copy.
*/
pick (value) {
if (value === undefined) {
return
}
if (this.type === 'object') {
value || (value = {})
let copy = {}
const properties = this.properties
if (properties) {
Expand All @@ -1205,7 +1207,6 @@ export default Component.extend({
}
return copy
} else if (this.type === 'array') {
value || (value = [])
return value.map((item) => {
const _copy = this.items ? this.items.pick(item) : {}
if (this.extends) {
Expand Down
78 changes: 68 additions & 10 deletions test/unit/schema/pick.test.js
Expand Up @@ -29,11 +29,8 @@ describe('Schema.pick', function () {
},
name: undefined,
price: undefined,
tags: [],
warehouseLocation: {
latitude: undefined,
longitude: undefined
}
tags: undefined,
warehouseLocation: undefined
})
})

Expand Down Expand Up @@ -172,7 +169,8 @@ describe('Schema.pick', function () {
name: 'foo',
beep: 'boop'
}
]
],
dimensions: {}
}

const copy = schema.pick(data)
Expand All @@ -186,17 +184,77 @@ describe('Schema.pick', function () {
},
price: undefined,
name: undefined,
tags: [],
tags: undefined,
roles: [
{
name: 'foo',
id: undefined
}
],
warehouseLocation: {
latitude: undefined,
longitude: undefined
warehouseLocation: undefined
})
})

it('should ignore undefined properties', function () {
const store = new JSData.DataStore()

const countrySchema = new JSData.Schema({
type: 'object',
properties: {
code: {
type: 'string',
indexed: true
}
}
})

store.defineMapper('country', {
schema: countrySchema
})

store.add('country', [
{
code: 'foo'
},
{
code: 'bar'
}
])

const addressSchema = new JSData.Schema({
type: 'object',
properties: {
uid: { type: 'string' },
tag: { type: ['string', 'null'] },
country: {
type: 'object',
extends: countrySchema,
get () {
return store.getAll('country', this.tag, { index: 'code' })[0]
}
}
}
})

store.defineMapper('address', {
schema: addressSchema
})

const address = store.createRecord('address', { uid: '123', tag: 'foo' })
const address2 = store.createRecord('address', { uid: '789', tag: 'beep' })

assert.deepEqual(address.toJSON(), {
uid: '123',
tag: 'foo',
country: {
code: 'foo'
}
})

assert.deepEqual(address2.toJSON(), {
uid: '789',
tag: 'beep',
country: undefined
})
})
})

0 comments on commit 8357c11

Please sign in to comment.