Skip to content

can skip computed properties calculation to prevent recursion problems #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ module.exports = (Model, options) => {
return next()
}

// Skip if specified in options
if (ctx.options.skipComputed) {
return next()
}

return Promise.map(Object.keys(options.properties), property => {
const callback = options.properties[property]

Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,15 @@ describe('loopback computed property', function() {
expect(itemFromDb).to.not.have.property('promised')
})
})

it('should not compute if requested with "skipComputed" attribute', function() {
const { id } = this.itemOne

return new Promise(function(res) {
Item.find({ where: { id } }, { skipComputed: true }).then(function(item) {
expect(typeof item[0].readonly).to.be.equal('undefined')
res()
})
})
})
})