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.

Static variables declared on advanced schemas are not loaded into the model

See original GitHub issue

When declaring a static variable on a class loaded with loadClass into the schema, the static variable does not get loaded into the model.

In order for it to work, you need to explicitly declare the static variable through the classic function property schema.statics approach.

In order to reproduce:

  1. Create a model through advanced schemas
  2. Add a static variable, example: static TEST = true;
  3. Try accessing the static variable from the model (it will not exist)

Mongoose v5.9.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
IslandRhythmscommented, May 6, 2021

We’ll be implementing this soon

0reactions
meircarloscommented, May 6, 2021

Sure, but the static method findByFullName also belongs to the PersonClass and it’s accessible from the Person model, why would this behavior be avoided for static variables when it works correctly for static methods?

Otherwise the workaround I’m currently doing is duplicating the static variable and adding it to the schema statics, as you can see on the commented lines of code

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reason for not using static variables? - Stack Overflow
No. Heap is for data allocated via malloc() and, in the case of C++, new . The pointers are stored wherever you put...
Read more >
Creating a routine and declaring a static variable - 8.0
In the Repository tree view, create a new routine MyRoutine . Declare a static variable in the routine and set its value as...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
Static Variables in C - GeeksforGeeks
A normal or auto variable is destroyed when a function call where the variable was declared is over. For example, we can use...
Read more >
Top 75 Talend Interview Questions and Answers in 2023
Generic Schema: This schema is not tied to any particular source ... Yes, you can do that by declaring a static variable within...
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