Skip to content

Creating model with autoFetched association hasMany #242

@gaetsd

Description

@gaetsd

Hi, I write this little test to explain my issue:


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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions