Skip to content

Commit 28621a5

Browse files
committedJul 27, 2018
test(document): repro #6754
1 parent 7965494 commit 28621a5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎test/docs/transactions.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,34 @@ describe('transactions', function() {
135135
session.commitTransaction();
136136
});
137137
});
138+
139+
it('populate (gh-6754)', function() {
140+
const Author = db.model('Author', new Schema({ name: String }), 'Author');
141+
const Article = db.model('Article', new Schema({
142+
author: {
143+
type: mongoose.Schema.Types.ObjectId,
144+
ref: 'Author'
145+
}
146+
}), 'Article');
147+
148+
let session = null;
149+
return db.createCollection('Author').
150+
then(() => db.createCollection('Article')).
151+
then(() => db.startSession()).
152+
then(_session => {
153+
session = _session;
154+
session.startTransaction();
155+
return Author.create([{ name: 'Val' }], { session: session });
156+
}).
157+
then(authors => Article.create([{ author: authors[0]._id }], { session: session })).
158+
then(articles => Article.findById(articles[0]._id).session(session)).
159+
then(article => {
160+
assert.ok(article.$session());
161+
return article.populate('author').execPopulate();
162+
}).
163+
then(article => {
164+
assert.equal(article.author.name, 'Val');
165+
session.commitTransaction();
166+
});
167+
});
138168
});

0 commit comments

Comments
 (0)
Please sign in to comment.