geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

Named associations foreign key differences #125

Closed zerocle closed 10 years ago

zerocle commented 10 years ago

given the following named association:

var Book = function() {
  this.belongsTo('Author', {model: 'User'} );
};

it seems that the model expects the following foreign key in the database: "author_user_id" however, the adapter is looking for "book_author_id."

It looks like the bug comes from

base.js:245 mainColName = mainName + assnName + 'Id';

which should be the following to be in sync with the model. mainColName = assnName + assnModelName + 'Id';

I hope this helps track this down and if I am incorrect, or using the named associations/postgres adapter incorrectly, please let me know. Thanks for all the great work!

mde commented 10 years ago

Nice catch -- fixed and tested in 388664b2935cb32d314d25f3e0550cd3559658af, pushed to NPM in v0.4.7.