Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

strange issue with underscores in column names (using mongo) #195

Closed
ehudros opened this Issue · 4 comments

3 participants

@ehudros

Well, this is kinda weird...
I have a model definition like this:
var Game = function () {
this.defineProperties({
id: {type: 'string', required: true},
board_layout: {type: 'array'}
});

this.adapter = "Mongo";
};

When trying to access a loaded game's board_layout property I keep getting 'undefined', no matter what I do. The only way I was able to work around it was to not use an underscore in the property name. I was able to reproduce it with other field types as well (int etc.). As long as it had an underscore in the column name, it came back as undefined.
I'm on windows, using the latest mongo/geddy.

@mde
Owner

By default Geddy camelizes column names in the model instances. (You can set model.forceCamel = false in your config to override this behavior, but I would not recommend it because it's not the happy path.) DB column-names end up in snake_case, but get correctly translated to camelCase in the JS objects.

@ehudros

Got it, had to set the property name to boardLayout in the model definition and that sorted things out.
Is this documented anywhere? It's quite unintuitive for the column name to be different in the DB and the ORM.

@mde
Owner

I don't think this is documented anywhere yet. I'll add it to the docs for the Model project (which is where all the new Geddy model work has moved).

But It doesn't seem t any more unintuitive to me than having a controller called FooBars where the file name for the controller is foo_bars.js. It's just mapping the name into whatever the correct casing is for that particular usage. Underscores are legal in JavaScript, but they're not normal JavaScript style.

@ehudros

Well, perhaps it's only unintuitive for people coming from Rails background - I'm used to controllers/model class names being camel cased, but not db columns :)

@Techwraith Techwraith closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.