Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

MySQL column name that starts with "style_" cannot be read from DB #545

Closed
JohnPostlethwait opened this Issue · 4 comments

2 participants

@JohnPostlethwait

I am building an application on an existing MySQL database.

One of the column names was "style_id". When I set up my model, all the properties were read out of the database just fine, except for this one named "style_id" which was always "undefined".

Doing SELECT * FROM fabrics; directly in MySQL would show me the style_id property just fine. Doing a simple geddy.model.Fabric.all( ... ); would never have a style_id that was not undefined.

When I changed "style_id" to "style_identifier" in my MySQL database, I would get the same "undefined" result. When I changed the column name to "identifier" all of a sudden it started selecting the value out of the database without any issue.

It seems it was the "style_" prefix it didn't like...

@mde
Owner

Model automatically converts properties in 'snake case' (i.e., lowercase, underscores) to camel case. These will still be in snake case in the database columns. You can turn this feature off by setting forceCamel to false in the model config.

@JohnPostlethwait

Something like this?

var MyModel = function () {
    this.forceCamel = false;

    // ...
};
@mde
Owner

It's global to the model lib, so just model.forceCamel.

@JohnPostlethwait

Great, thanks!

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.