I've to save a new message
onto the server and also send additional data to it
I've the following code
App.Message = DS.Model.extend({
body: DS.attr('string'),
messagethread_id: DS.attr('number')
});
// in controller
var msg = this.store.createRecord('message', {
body: messageBody,
messagethread_id: thread.id,
token: this.get('token')
});
msg.save();
As you can see the token isn't defined on the model so it isn't sent to the server. I need to send it but I don't need to retrieve that in any situation.
thanks in advance
The simplest thing: why don't you define also token in your model? Then you manage it server-side; for example when the token is not needed, you set it to null; in the server you can check if it is null or not; of course then your server will have to answer to GET request also with the token attribute (but you simply set it to null too);
or you can define two different models: a Message Model and a MessageWithToken Model; and then use the first one or the last one depending if you need to send token or not; also in this case you will have to manage things in your server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.