Permalink
Browse files

Virtual Attributes added

  • Loading branch information...
dreampulse committed Jul 25, 2014
1 parent a76f7e7 commit e91ed25692b53280b8f775f1055a4ae280a5207f
Showing with 47 additions and 2 deletions.
  1. +14 −0 browser-dist/modelizer-angular.js
  2. +14 −0 browser-dist/modelizer.js
  3. +14 −0 lib/model.js
  4. +1 −1 test/integration/shared/models.js
  5. +4 −1 test/orm.spec.js
@@ -969,6 +969,10 @@ Model.prototype._initObject = function(rootObject) {
obj[this.attrs[i].name] = null;
}
+ for (var i in this.virtualAttrs) {
+ obj[this.virtualAttrs[i].name] = null;
+ }
+
// create Attribute Objects (a sub structure)
for(var i in this.attrObjs) {
var attrObj = this.attrObjs[i]._initObject(rootObject);
@@ -1424,6 +1428,10 @@ Model.prototype.processSchema = function(schema) {
} else if (value._what == 'attr') {
this.attr(entry, value.filter);
+ // it is a virutal attribute
+ } else if (value._what == 'virtualAttr') {
+ this.virtualAttr(entry);
+
// it is a reference to another model
} else if (value._what == 'attrRef') {
this.attrRef(entry, value.ref);
@@ -1479,6 +1487,12 @@ Model.Attr = function() {
};
};
+Model.VirtualAttr = function(reference) {
+ return {
+ '_what' : 'virtualAttr'
+ };
+};
+
Model.Ref = function(reference) {
return {
'_what' : 'attrRef',
View
@@ -769,6 +769,10 @@ Model.prototype._initObject = function(rootObject) {
obj[this.attrs[i].name] = null;
}
+ for (var i in this.virtualAttrs) {
+ obj[this.virtualAttrs[i].name] = null;
+ }
+
// create Attribute Objects (a sub structure)
for(var i in this.attrObjs) {
var attrObj = this.attrObjs[i]._initObject(rootObject);
@@ -1224,6 +1228,10 @@ Model.prototype.processSchema = function(schema) {
} else if (value._what == 'attr') {
this.attr(entry, value.filter);
+ // it is a virutal attribute
+ } else if (value._what == 'virtualAttr') {
+ this.virtualAttr(entry);
+
// it is a reference to another model
} else if (value._what == 'attrRef') {
this.attrRef(entry, value.ref);
@@ -1279,6 +1287,12 @@ Model.Attr = function() {
};
};
+Model.VirtualAttr = function(reference) {
+ return {
+ '_what' : 'virtualAttr'
+ };
+};
+
Model.Ref = function(reference) {
return {
'_what' : 'attrRef',
View
@@ -737,6 +737,10 @@ Model.prototype._initObject = function(rootObject) {
obj[this.attrs[i].name] = null;
}
+ for (var i in this.virtualAttrs) {
+ obj[this.virtualAttrs[i].name] = null;
+ }
+
// create Attribute Objects (a sub structure)
for(var i in this.attrObjs) {
var attrObj = this.attrObjs[i]._initObject(rootObject);
@@ -1192,6 +1196,10 @@ Model.prototype.processSchema = function(schema) {
} else if (value._what == 'attr') {
this.attr(entry, value.filter);
+ // it is a virutal attribute
+ } else if (value._what == 'virtualAttr') {
+ this.virtualAttr(entry);
+
// it is a reference to another model
} else if (value._what == 'attrRef') {
this.attrRef(entry, value.ref);
@@ -1247,6 +1255,12 @@ Model.Attr = function() {
};
};
+Model.VirtualAttr = function(reference) {
+ return {
+ '_what' : 'virtualAttr'
+ };
+};
+
Model.Ref = function(reference) {
return {
'_what' : 'attrRef',
@@ -48,7 +48,7 @@ var ContentModel = new model("Content")
.attr("stuff", Type.string)
.attr("name", Type.string)
.attr("password", Type.string)
- .attr("afterRead", Type.string)
+ .virtualAttr("afterRead", Type.string)
.operation("register")
.operation("login")
.operation("logout")
View
@@ -4,6 +4,7 @@ var Q = require('q');
describe('Modelizer', function() {
var model = require('../lib/modelizer');
var Attr = model.Attr;
+ var VirtualAttr = model.VirtualAttr;
var Ref = model.Ref;
var Link = model.Link;
var RefArray = model.RefArray;
@@ -653,7 +654,9 @@ describe('Modelizer', function() {
aOperation : Operation(),
- aFactory : Factory()
+ aFactory : Factory(),
+
+ aVirtual : VirtualAttr(Types.string)
});
MyModel9.connection(connector);

0 comments on commit e91ed25

Please sign in to comment.