dresende / node-orm2

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

Added support for changing accessor names on reverse relation #640

Closed raulcesar closed 2 years ago

raulcesar commented 9 years ago

First let me say thank you for this awesome library! I tried 2 others for a new project I am starting, but had various issues. This one has hit the sweet spot so far!

One slight issue I had was that when defining a hasMany relation, one can change the name of the accessor functions (i.e. get, set, has, del or add), but the accessors generated for the "reverse" relationship seem to be fixed. For instance, when I defined a hasMany between "users" and "roles" on the Role model (with option "reverse='roles'), I could change the method "addUsers" to "addUser", but was unable to change the reverse "addRoles" method (that was generated on the User model object.

I added support for changing these names by specifying these parameters in options object:

dxg commented 9 years ago

Looks good, but could you also try adding some tests? That file looks a lot less scary when you set tab size to two.

raulcesar commented 9 years ago

Hello Arek,

Will do. Just one detail I would like to clear up before finishing up the tests and sending a PR. You linked to the "association-hasmany.js" file. Since my changes where basically to the "reverse", would it be ok to create a separate association-hasmany-reverse.js file?

On Fri, May 15, 2015 at 12:45 AM, Arek W notifications@github.com wrote:

Looks good, but could you also try adding some tests https://github.com/dresende/node-orm2/blob/master/test/integration/association-hasmany.js ? That file looks a lot less scary when you set tab size to two.

— Reply to this email directly or view it on GitHub https://github.com/dresende/node-orm2/pull/640#issuecomment-102245322.

dxg commented 9 years ago

Yeh, sure