Permalink
Browse files

Added default relationship builder.

  • Loading branch information...
1 parent a71f970 commit ef2d94e7903984f345445c6598f734560149c343 @DavidSouther committed Jun 9, 2012
Showing with 8 additions and 0 deletions.
  1. +8 −0 js/core/src/Runtime.js
View
@@ -337,6 +337,7 @@
return this;
}
});
+ // Mutaccs for has_a and is_a
} else {
_.extend(definition.Constructor.prototype[rel_name], {
get: function(longGet) {
@@ -348,6 +349,13 @@
if(undefined === this.__relationships[field]) {
// Just need the one...
this.__relationships[field] = ec._instances[relationship.to.type][this[relationship.property]()];
+ // Make sure we found one
+ if(undefined === this.__relationships[field]){
+ // If not, create it.
+ var key = {};
+ key[ec.definition(relationship.to.type).key] = this[relationship.to.property]();
+ this[rel_name](ec.build(relationship.to.type, key))
+ }
}
return this.__relationships[field];
},

0 comments on commit ef2d94e

Please sign in to comment.