You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Creating model with autoFetched association hasMany #242
var orm = require('orm');
orm.connect("mysql://root@127.0.0.1/test?debug=true", function (err, db){
console.log("CONNECTED TO DATABASE");
///////////////////////
// CREATE THE PARENT
///////////////////////
var Person = db.define('person', {
name : String
});
///////////////////////
// CREATE THE CHILD
///////////////////////
var Animal = db.define('animal', {
name : String
});
///////////////////////
// LINK THEM UP
///////////////////////
Person.hasMany("pets", Animal,{}, {
autoFetch: true
});
///////////////////////
// Sync
///////////////////////
db.sync(function(){
console.log("SYNC'D DB `test`");
///////////////////////
// Test insert
///////////////////////
var John = new Person();
John.name = "John";
John.save(function(err,obj){
if(err)
console.log("err: " + err);
console.log(obj);
console.log("END");
});
});
});
When I execute this code, I have the error:
No associations defined
But when I remove the autoFetch option, it working correctly.
Can you help me, please.
if I define autoFetch and reverse option, the reversed table's query will load this table. e.g. group has many user, reversed user has group, if this is autoFetched, if I get a group, there is a array in group object that the users of group, but when I get a user, there also is a array in user object! how can I get "one-side" direction of autoFetch?
when I use .count to getXXXX of hasMany, the generated SQL is wrong :-( e.g. if I write this:
Activity
dresende commentedon Jul 25, 2013
The error happens when you call
John.save()?starwing commentedon Jul 26, 2013
I have meet this issue, too :-(
after remove autoFetch option, the error is gone.
btw, there are two issue related with this:
instead of this SQL is executed:
but just:
is that right behavior?
gaetsd commentedon Jul 26, 2013
Yes the error happens when I call
John.save(). There is the same issue when I use the create method like this:The error appears when
Person.create()is calledctaepper commentedon Jul 26, 2013
i can confirm this... this bug seems to come out of nowhere as it was working earlier...
Changes autoFetch to avoid autofetching if instance is not saved (it'…
dresende commentedon Jul 29, 2013
Please try this latest commit.
gaetsd commentedon Jul 30, 2013
This last version works fine. I've tried it with my test and in my application and it's working. Thanks a lot.