Good vs. Evil

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
58 so....the users table holds the username and the user id of everyone. in the lobby table is an object that holds the user id's and usernames of everyone that joined that lobby.

hooray for double data storage >_>
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
55 so.....for some reason it seems that mongoose removes all the values from the object you pass to the save function that are not in the schema (which makes sense) BEFORE your middle-ware is called (Which is the most retarded thing ever).
explanations as to why it annoys me to say the least.
lets say I want to store an int in my mongodb you get something like
numbers.save({someNumber :1})
now, lets say that what I actually want to store is this number divided by 2 (and doing it every time I get the number out of the database is not an option)
I would make a small function as middleware
Code:
numbersModel.pre("save",function(next){
    this.someNumber=this.inputNumber/2;
    this.inputNumber=null
   next()
})
//back in the controller
numbers.save({inputNumber:2})
except that this doesn't work as the database schema doesn't have a field inputNumber thus it gets removed before your middle ware gets called.
Sure, I could reuse someNumber but I find that both ugly and I doubt it would work if the type of value you store is different then the one you pass it.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
53 /me waits until someone points out an obvious solution that I just happen to miss that is also nice looking (thus not making my own save function that needs to be called first which executes the save function of mongoose >_> )
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
49 because I went with the function that calls the save function "fix"
IT LOOKS SO BAD!!! ARGH!!
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
49 this prisoner may or may not have been too "kind"
upload_2016-2-4_14-58-42.png