question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promise in getterMethods

See original GitHub issue

I wanna do the following getter in my model:

getterMethods: {
      objectLabel: function() {
         if (this.zoneId) {
          db.WarehouseZone.findOne({
            where: {
              id: this.zoneId
            }
          }).then(zone => {
            return `${zone.zoneId}-${this.aisle}-${this.bin}-${this.level}`;
          });
         } else {
          return `${this.aisle}-${this.bin}-${this.level}`;
         }
        return `${this.zoneId ? `${this.zoneId}-` : ''}${this.aisle}-${this.bin}-${this.level}`;
      }
    }

How can I do that with promises? Is here exists any callback or something other?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
janmeiercommented, Aug 30, 2016

Works fine for me

var WarehouseLocation = sequelize.define('whl');
WarehouseLocation.addHook('afterFind', function(result) {
  console.error('result', result);
  return result;
});

return sequelize.sync({
  force: true,
  logging: console.log
})
  .then(() => {
    return WarehouseLocation.findAll()
  })
  .finally(() => sequelize.close());
Executing (default): SELECT "id", "createdAt", "updatedAt" FROM "whls" AS "whl";
result []

Please try to create a SSCCE - its really, really hard to help you if I can’t replicate the problem

0reactions
janmeiercommented, Aug 30, 2016

Please read the link on SSCCE and post a complete, self-contained, copy paste-able test case that replicates the issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Async Getters and Setters. Is it Possible? | by David Barral
Async functions always return a promise. If the return value of an async function is not explicitly a promise, it will be implicitly...
Read more >
Async getterMethods in sequelize - node.js - Stack Overflow
The getterMethod is synchronous so you would not be able to run a promise and return the resolved value on the model instance....
Read more >
getter - JavaScript - MDN Web Docs - Mozilla
Getter properties are defined on the prototype property of the class and are thus shared by all instances of the class. Unlike getter...
Read more >
T287 Use promises for image info getter methods in ...
Use promises for image info getter methods in UploadWizardUpload. Closed, DuplicatePublic. Actions. Edit Task; Edit Related Tasks.
Read more >
JavaScript Getter and Setter (with Examples) - Programiz
In JavaScript, getter methods are used to access the properties of an object. For example,. const student = { // data property firstName:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found