dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 377 forks source link

Parse attributes from db before creating object #556

Open deepwell opened 9 years ago

deepwell commented 9 years ago

I think it would be very handy to be able to add a parse function after an object has been retrieved before instantiating it.

My use case is that the database has field names with underscores, "field_name", but in JavaScript, and the API returns them as camel case "fieldName".

This is exactly what bookshelf.js supports with parse/format: http://bookshelfjs.org/#Model-parse

yuklai commented 9 years ago

Up vote on this request. :)

visla commented 9 years ago

+1

ierceg commented 9 years ago

+1

visla commented 9 years ago

I just remembered you could use mapsTo in your field definition to avoid this problem. You need it for each field, but its one way to do it.