Skip to content
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

hasOne ignores mapsTo #638

Closed
ierceg opened this issue May 12, 2015 · 8 comments
Closed

hasOne ignores mapsTo #638

ierceg opened this issue May 12, 2015 · 8 comments

Comments

@ierceg
Copy link

ierceg commented May 12, 2015

I have a model defined with mapsTo for each property (table is snake_case while model is camelCase). If I use hasOne to associate it to another model, the values of association fields are always null. I have tried the following alternatives:

  1. Defining association field name as it appears in the model. This leads to an exception due to ORM trying to insert a row with camelCase field.
  2. Doing help in development #1 but also changing the code in Utilities.js from:
    new_obj[obj].mapsTo = obj;

to

    new_obj[obj].mapsTo = new_obj[obj].mapsTo || obj;

This 2nd approach works in my tests but it broke other unit tests.

Before I continue I would like to know if I'm on the right track here. Are associations defined per model property name (camelCase in my case) or per table column name (snake_case in my case)?

@dxg
Copy link
Collaborator

dxg commented May 12, 2015

Not sure I understand the question, but maybe neither?
I don't think I ever tested mapsTo with associations. The functions in utilities.js are really confusing to work with.

@dxg
Copy link
Collaborator

dxg commented May 12, 2015

I've made some changes to master. They won't necessarily fix your problem, but they include tests.

Can you please run your code against master, and either add a failing test case, give me a code sample, or tell me how to make it fail?

@ierceg
Copy link
Author

ierceg commented May 12, 2015

@dxg Seems to be fixed - I tried two different tests and both passed. Thanks for this!

@ierceg
Copy link
Author

ierceg commented May 12, 2015

@dxg I misspoke - one test is still failing, I just didn't have it correctly configured. I'll add the failing test case.

@ierceg
Copy link
Author

ierceg commented May 13, 2015

@dxg I rechecked, again, and it works alright. It's the mapped name that has to be specified in the hasOne (I had column name and then it reverts to the behavior of using NULL for the value of the relationship field)

@ierceg
Copy link
Author

ierceg commented May 13, 2015

@dxg When do you expect to bump the package version?

@dxg
Copy link
Collaborator

dxg commented May 14, 2015

Just published 2.1.25

@dxg dxg closed this as completed May 14, 2015
@ierceg
Copy link
Author

ierceg commented May 14, 2015

@dxg Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants