Hi there. A time ago, I had to disable classTransformer (in useExpressServer) because it didn't work fine with mongoose models, but now, I would like to take advantage of classTransformer to transform the query params to an object, so it would be nice to have the ability to enable classTransformer only for the input and keep it disabled for output. Is it posible?
no I don't think its possible right now. What problem do you have with mongooose models? Maybe @Exclude can help you in your mongoose models?
It would be nice to have a option to disable transform on response.
Return a sequelize instance or mongoose instance both throw error.
I now doing this to disable transform on response:
import { KoaDriver } from 'routing-controllers/driver/koa/KoaDriver'
const originHandleSuccess = KoaDriver.prototype.handleSuccess
KoaDriver.prototype.handleSuccess = function () {
this.useClassTransformer = false
return originHandleSuccess.apply(this, arguments)
}
thats why you should use typeorm instead of sequelize or mongoose 馃槤 . But seriously it should be easily fixed if you do something like this in your models:
@Exclude()
_id: string;
@Expose()
get id() {
return this._id.toString(); // or some other method that normalizes that id
}
Closing as a duplicate in favor of #226.
Please subscribe there to be notified when the required changes land.
@ruiming Nice workaround, thanks!
@pleerock I really appreciate the work you've done with routing controllers so far, it's great! But I believe a library like this should be agnostic of any data mappers being used rather than being developed to suit only TypeORM.
It does not "suit typeorm". class-transformer is generic serializer and does work with object. In mongodb you have complex MongoID object and it simply tries to serialize it as well. The issue with complexity of mongoid object, not with class-transformer.
thats why you should use typeorm instead of sequelize or mongoose
I was referring to your comment, which implies you shouldn't be using anything other TypeOrm with routing-controllers.
I didnt say that routing-controllers cannot be used with anything else except typeorm. It was simple advice and a bit of joke as you can see from "馃槤" smile I used.
Okay that's my bad 馃槅 sorry for misunderstanding!
BTW you should really try TypeORM 馃槤
If TypeORM had full support for Mongoose then I would gladly, but unfortunately it doesn't 馃槩 I'm working on a similar project to TypeORM specifically for Mongoose myself at the moment to compensate 馃槈
I'm working on a similar project to TypeORM specifically for Mongoose myself at the moment to compensate
+1 to that!
It does not have all features mongoose has, but it does have all required features to make really good applications using mongodb.
The last I checked, it had only "basic" MongoDB support. Which is great, I'm glad to see it going in that direction and I mean no offense or to put down TypeORM in any way because I think it's an absolutely fantastic project. But Mongoose is extremely advanced and has a lot of features which personally I could not feel like I could do without, I am very heavily invested in that particular technology in a lot of projects. My TypeORM-like project will just be a simple enough tool that converts classes into Mongoose compatible schemas and leave mostly everything else up to Mongoose. All hail Mongoose 馃檹 馃摽
Those using Sequelize: you can return the result of your model instance's toJSON method to the action method in order for class-transformer's serialization to work properly
Any update about this?
This is my workaround:
// Disable classToPlain class-transformer
require('class-transformer')['classToPlain'] = function (obj: object) {
return JSON.parse(JSON.stringify(obj))
}
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
It would be nice to have a option to disable transform on response.
Return a sequelize instance or mongoose instance both throw error.
I now doing this to disable transform on response: