Open nicolasroger17 opened 10 years ago
I am trying to make a timer server that perform a request with the orm.
I defined my models using express :
app = express(); app.use(orm.express(conf, { define: function (db, models) { // les utilisateurs models.user = db.define("user", { lastName : String, firstName : String, emailAddress : String, address : String, city : String, zipCode : Number, phone : String, password : String }, [...]
I can use the models using the req object :
app.get("/", function (req, res) { // req.models is a reference to models used above in define() req.models.person.find(...); });
,but I don't know how to make a request when it's not a request from the client, so without the variable "req".
I have access to app so I would like to do something like :
app.models.person.find();
but it doesn't work.
If someone knows the relation between "app" and the models I defined, this would be very helpful.
Thank you.
I approach this problem without using the built in orm.express middleware. I have a general 'connection' file I can require from anywhere. See here. It is used without req here and mixed into req here.
orm.express
req
I have also used the pattern @dxg is recommending, and so far it's worked great!
I am trying to make a timer server that perform a request with the orm.
I defined my models using express :
I can use the models using the req object :
,but I don't know how to make a request when it's not a request from the client, so without the variable "req".
I have access to app so I would like to do something like :
but it doesn't work.
If someone knows the relation between "app" and the models I defined, this would be very helpful.
Thank you.