Static variables declared on advanced schemas are not loaded into the model
See original GitHub issueWhen 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:
- Create a model through advanced schemas
- Add a static variable, example: static TEST = true;
- Try accessing the static variable from the model (it will not exist)
Mongoose v5.9.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’ll be implementing this soon
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