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

Wolfpack works with waterline associations? #11

Closed
albertosouza opened this issue Aug 4, 2014 · 4 comments
Closed

Wolfpack works with waterline associations? #11

albertosouza opened this issue Aug 4, 2014 · 4 comments

Comments

@albertosouza
Copy link

When trying to set a model with associatons am getting the error

The model is User and has one model Image associated

/home/a/projetos/we-up/node_modules/wolfpack/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:82
    throw new Error('Trying to access a collection ' + collection + ' that is 
          ^
Error: Trying to access a collection images that is not defined.
    at ForeignKeys.findPrimaryKey (/home/a/projetos/we-up/node_modules/wolfpack/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:82:11)
    at ForeignKeys.replaceKeys (/home/a/projetos/we-up/node_modules/wolfpack/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:53:27)
    at new ForeignKeys (/home/a/projetos/we-up/node_modules/wolfpack/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:30:10)
    at new module.exports (/home/a/projetos/we-up/node_modules/wolfpack/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema.js:30:17)
    at wolfpack (/home/a/projetos/we-up/node_modules/wolfpack/lib/wolfpack.js:106:16)
    at Object.<anonymous> (/home/a/projetos/we-up/tests/integration/controllers/UserController.test.js:33:15)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.Module._extensions..js (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/lib/hook.js:102:13)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /home/a/projetos/we-up/node_modules/mocha/lib/mocha.js:183:27
    at Array.forEach (native)
    at Mocha.loadFiles (/home/a/projetos/we-up/node_modules/mocha/lib/mocha.js:180:14)
    at Mocha.run (/home/a/projetos/we-up/node_modules/mocha/lib/mocha.js:382:31)
    at Object.<anonymous> (/home/a/projetos/we-up/node_modules/mocha/bin/_mocha:381:16)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.Module._extensions..js (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/lib/hook.js:102:13)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at runFn (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/lib/command/common/run-with-cover.js:114:16)
    at /home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/lib/command/common/run-with-cover.js:232:17
    at /home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/lib/util/file-matcher.js:56:16
    at /home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/lib/util/file-matcher.js:35:9
    at Object.next (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/lib/fileset.js:41:14)
    at Fileset.emit (events.js:95:17)
    at Fileset.next (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:343:12)
    at Fileset.Glob._processEmitQueue (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:310:12)
    at Fileset.Glob.emitMatch (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:290:8)
    at Fileset.Glob._finish (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:230:8)
    at Fileset.<anonymous> (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:183:27)
    at Fileset.cb (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:368:11)
    at Fileset.<anonymous> (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:483:32)
    at Fileset.cb (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:368:11)
    at Fileset.<anonymous> (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:483:32)
    at Fileset.cb (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:368:11)
    at Fileset.<anonymous> (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:450:14)
    at Fileset.Glob._afterReaddir (/home/a/projetos/we-up/node_modules/grunt-mocha-istanbul/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:695:17)
    at Object.oncomplete (fs.js:107:15)
@fdvj
Copy link
Owner

fdvj commented Aug 4, 2014

Unfortunately I haven't had the time to test or write specs on waterline's new associations. Could you post a sample of your model code and the association? Waterline asynchronously loads collection and keeps a reference to them, so with wolfpack I had to reuse that async logic and create a sync version of it, so you could instantiate a model synchronously. There are still parts of waterline that I haven't tested that could be using this async load features. I'm guessing associations is one, so I'll need to write that part.

Again, I'll be really grateful if you could post a sample model with associations so I can test it locally, before launching a release version.

Thx

@albertosouza
Copy link
Author

User model: https://github.com/wejs/we/blob/master/api/models/User.js
Images model: https://github.com/wejs/we/blob/master/api/models/Images.js

I think i is possibli to change association to string or array and do the controller test.

@fdvj
Copy link
Owner

fdvj commented Aug 5, 2014

Associations are pretty complex (on the waterline side). As explained before, waterline loads the collections asynchronously. Associations is one reason they do that. Also, since we are now dealing with joins, wolfpack is outdated on its mock result methods. I'm working on a feature that will allow to mock results conditionally, which will solve this issue. However, since that is still in progress, what I'm gonna do for RC2 is to remove support for associations completely. I don't believe that you should change your code to allow wolfpack to execute. Your code is your code, wolfpack is just a testing suite, so wolfpack should handle your code just like waterline would do. What I will do instead is, if I find any associations, im gonna remove them so they don't get initialized and change them to json. This should allow current result mocker to keep working while the new version is in development, so your code will work with the current wolfpack, you will be able to mock results, only thing though is that the associated field won't be an instance of the model.

Im gonna post here once RC2 is ready with those changes. Thanks for sharing your code.

@fdvj
Copy link
Owner

fdvj commented Nov 8, 2014

Associations removed in new v0.3.0 release https://github.com/fdvj/wolfpack/releases/tag/v0.3.0

@fdvj fdvj closed this as completed Nov 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants