8000 Merge branch 'master' into revert-502-fix-deepMixIn · correct-js/js-data@6e0f561 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e0f561

Browse files
authored
Merge branch 'master' into revert-502-fix-deepMixIn
2 parents 5422ec5 + 07f07c2 commit 6e0f561

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ operating system:
1010

1111
## Steps to reproduce
1212

13-
<It's helpful to have a code example - consider forking this plunk template and adding reproducible code that will help resolve your issue: https://next.plnkr.co/edit/YmRdhVMRfc1qpm22>
13+
<!---
14+
It's helpful to have a code example - consider one of these options to quickly provide a
15+
reporducible example that will help others with this issue:
1416
15-
<steps_to_reproduce>
17+
1) Fork this Plunker https://next.plnkr.co/edit/YmRdhVMRfc1qpm22
18+
2) Use Runkit.com - ie: https://runkit.com/crobinson42/github-com-js-data-js-data-issues-501
1619
1720
Thanks!
21+
-->
22+
23+
<steps_to_reproduce>

src/DataStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const props = {
178178
const inverseDef = def.getInverse(mapper)
179179
const currentParentId = currentParent ? utils.get(currentParent, def.getRelation().idAttribute) : undefined
180180

181-
if (currentParent && currentParentId !== undefined && currentParentId !== value) {
181+
if (inverseDef && currentParent && currentParentId !== undefined && currentParentId !== value) {
182182
if (inverseDef.type === hasOneType) {
183183
safeSetLink(currentParent, inverseDef.localField, undefined)
184184
} else if (inverseDef.type === hasManyType) {

test/unit/collection/add.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,27 @@ describe('Collection#add', function () {
298298
// console.log('\tinject 10,000 users time taken: ', new Date().getTime() - start, 'ms')
299299
// console.log('\tusers age 40-44', User.between(40, 45, { index: 'age' }).length)
300300
})
301+
it('should update a records relation when the inverse relation does not exist', function () {
302+
const store = new JSData.DataStore()
303+
store.defineMapper('user')
304+
store.defineMapper('post', {
305+
relations: {
306+
belongsTo: {
307+
user: {
308+
localKey: 'user_id',
309+
localField: 'user'
310+
}
311+
}
312+
}
313+
})
314+
const [user1, user2] = store.add('user', [{
315+
id: 1, name: 'John'
316+
}, {
317+
id: 2, name: 'Jane'
318+
}])
319+
const post = store.add('post', { id: 2, title: 'foo', user_id: 1 })
320+
assert.strictEqual(post.user, user1)
321+
store.add('post', { id: 2, title: 'foo', user_id: 2 })
322+
assert.strictEqual(post.user, user2)
323+
})
301324
})

0 commit comments

Comments
 (0)
0