Atlantis-Software / offshore

An adapter-based ORM for Node.js with support for mysql, mongo, postgres, redis, and more
MIT License
38 stars 15 forks source link

{type: json} and {type:array} primaryKey error #18

Closed dandanknight closed 8 years ago

dandanknight commented 8 years ago

Hi, I've been following the deepPopulate pull req thread on balderdashy, and it's lead me here. I've installed the atlantis-software/waterline#deepPopulate branch, and am using it in place of the one that ships with sails.js, and it works except for when there is a type : "json" or type : "array" attribute in a model, when I then get the error...

this.index(alias, child[this.paths[this.path].children[alias].primaryKey], child);
Cannot read property 'primaryKey' of undefined

I experimented using someone's suggestion on that thread and found that adding the additional test case to the if on line 84 of deepCursor.js...

 if (child && this.paths[this.path].children[alias]) {
    this.index(alias, child[this.paths[this.path].children[alias].primaryKey], child);
 }

and it seems to fixes this. Are you aware of this issue already? I couldn't see anything in the PRs.

Also, a general question. How would I use offshore in place of waterline in a sails project? Can I just point sails at offshore instead of waterline using an npm link or something?

Thanks, Dan

atiertant commented 8 years ago

Hi, i knew this problem, i was waitting a PR but i'll had this test. i 'll post here when it's done.

for your more general question, i don't use Sails.js so i couldn't answer you but for now offshore haven't any breaking change with waterline except if adapter try to access waterline object but this could be solved using:

offshore.initialize({ compat: "waterline", ...

i would love a howTo to had in wiki

pdavid0 commented 8 years ago

Hi @atiertant ! I have the same questions has @dandanknight . The fork is great but could use a little bit more doc on how to replace waterline. I would be willing to push a doc PR, but I'm still facing issues.

Where do I put offshore.initialize({ compat: "waterline", ... ? I tried :

var Offshore = require('offshore');
Offshore.initialize({ compat: "waterline" });

In bootstrap.js but it says that its not a function.

Further more : Do I have to declare my models this way : module.exports = Offshore.Collection.extend({ attributes:{} }); ? Or installing offshore is enough ?

Thanks

Edit : Installing atlantis-software/waterline#deepPopulate and manually adding the fix mentioned above fixes my issues.

atiertant commented 8 years ago

hi, @pdavid0 and @dandanknight this could help sails-hook-orm-offshore