-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp properties do not respect turning off auto-camel #238
Comments
Could you give me some more specifics? You say "when I get data back." Does that mean you're querying the DB directly, or are you saying you're getting model instances with inconsistently named properties? Are you turning off the auto-camel feature in your config? |
So, this: UserModel.first(query, function (err, data) {
console.log('DATA: ', data)
}); Gives me:
In the database its I'd like it to be |
Ah, so you have the auto-camel turned off. The issue here is that the timestamp properties are managed by the library, so they are outside the normal flow. I'll update the title of this issue to reflect that. |
Oh, is that an option somewhere? cmd+f'd camel and didn't see anything. I haven't actually set anything in that regard. |
Ok, coming back to this, I found in the source the From reading the code it appears that it will convert, like this.defineProperties({
userId: { type: 'string', required: false },
familyId: { type: 'string', required: false },
permission_level: { type: 'number', required: false }
}); to look like this.defineProperties({
user_id: { type: 'string', required: false },
family_id: { type: 'string', required: false },
permission_level: { type: 'number', required: false }
}); Is that possible? |
This is an option you set when you bootstrap Model. If you're seeing snake_case properties on your instantiated items, you've likely got it set (to https://github.com/geddy/model/blob/master/lib/index.js#L740 Anything outside this The I'd be happy to merge a PR that makes this more robust and consistent, but in general it's pretty edge-casey because properties on JS objects in general should be camel. :) |
OK, I think that helps. So, properties aren't actually 1 to 1 with the column names in my DB. I was picturing that "define properties" meant defining props that actually match with the column names. I also agree JS objects should be camel. Maybe I'll just do everything in camelCase and then just before returning the JSON to the client go back and snake case everything or when receiving data convert all snake case to camel before giving it to model. |
Model uses convention very heavily. It converts back and forth pretty freely between various formats for property and constructor (datatype) names: JS model name is PascalCase, singular -- SnowDog So the properties are 1-to-1 with the columns, with the names being translated back and forth automatically according to convention. |
In the database
created_at
andupdated_at
are stored with underscores along with everything else such asfirst_name
. When I get data back I get{createdAt: '...', 'first_name': ...}
which is inconsistent. I wouldn't care if it changed everything to camel case likefirstName
, but it doesn't so its kinda weird. Is there anyway I can turn that off without having to manually change that manually everywhere after getting the model data?The text was updated successfully, but these errors were encountered: