cayasso/oomvc — Issue #26: BUG: collections with alternative keys fail
Author: noctivityinc
Created: 2011-11-04 20:55:44+00:00
State: open
Labels: Bug

Assume your goals model has this for it's collections object:

collections: [{key: 'tasks', foreignKey: 'goal_id'}, {key: 'bars', foreignKey: 'foo_id'}],

and your Bars model looked like this:

```
(function(Model){

Model.Bar = Model.Extension.extend('Bar', {

schema: {
foo_id: { dbName: 'goal_id', type: Number, required: true },
...
},

connection: {
key: 'task',
...
}

}
);

})(Lowes.My.Model);
```

So, as can be seen, the Bars model has a connection key pointing to an object called 'task' and not 'bar' a call to

goal.bars.count()

will fail and return an error saying that goal does not have a collection called bars.

For the record, if you change the foreign_key to goal_id and change the key in the schema above to goal_id, the same thing happens. You still get an error.

A test case for this issue has been created called alternativeConnectionKey in controllers.js. You will also need

https://github.com/cayasso/oomvc/blob/master/GoalFoo.js and
https://github.com/cayasso/oomvc/blob/master/TaskBar.js and the updated
https://github.com/cayasso/oomvc/blob/master/example/test/index.html