Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Enable adding Model associations directly on Model definition.
Browse files Browse the repository at this point in the history
Example:

var Product = db.define("product", {
    ...
});
var Sale = db.define("sale", {
    product: Product,
    ...
});

That property is the same as doing this association:

Sale.hasOne("product", Product);
  • Loading branch information
dresende committed May 31, 2012
1 parent eb1aced commit d021b6d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/orm.js
Expand Up @@ -491,6 +491,9 @@ ORM.prototype.define = function (model, fields, colParams) {
fields[k] = { "type": typeof fields[k]() };
} else if (o instanceof Date) {
fields[k] = { "type": "date" };
} else if (fields[k]._ORM) {
Model.hasOne(k, fields[k], { autoFetch: true });
delete fields[k];
} else {
fields[k] = { "type": fields[k] };
}
Expand Down

0 comments on commit d021b6d

Please sign in to comment.