Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion libs/base_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,14 @@ BaseModel._create_table_query = function(table_name,schema){
continue;
}
field_type = schemer.get_field_type(schema, k);
rows.push(util.format('"%s" %s',k,field_type));
rows.push(
util.format(
'"%s" %s %s',
k,
field_type,
schema.fields[k]["static"] ? "static" : " "
)
);
}

var partition_key = schema.key[0],
Expand Down Expand Up @@ -371,6 +378,11 @@ BaseModel._get_db_table_schema = function (callback){
db_schema.key = [[]];
db_schema.key[row.component_index+1] = row.column_name;
}
else if(row.type == 'static'){
if(!db_schema['static'])
db_schema['static'] = [];
db_schema['static'].push(row.column_name);
}
if(row.index_name){
if(!db_schema.indexes)
db_schema.indexes = [];
Expand Down
41 changes: 41 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ describe('Apollo > ', function(){
},
key:[["name", "surname"]]
};

var model_test_static = {
fields:{
username: "text",
id: {
"type":"uuid",
"default": {"$db_function": "uuid()"}
},
name:{
"type":"text",
"static":true
},
surname:{
"type":"text",
"static":true
},
favorites:{
"type":"text",
"static":false
},
likes:"text",
},
key:[["username"],"id"]
};

it('add model', function(){
var TestModel = ap.add_model("test1", model_test1);
Expand Down Expand Up @@ -180,6 +204,23 @@ describe('Apollo > ', function(){
assert.notOk(ins.complete_name);
});

it('adds model with static fields', function(done){
var TestModel = ap.add_model("teststaticfields", model_test_static);
TestModel._create_table(function (err) {
TestModel._get_db_table_schema(function(err, schema){
assert.notOk(err);
assert.property(schema,'static');
assert.isArray(schema['static']);
assert.equal(schema['static'][0], 'name');
assert.equal(schema['static'][1], 'surname');
assert.isFunction(TestModel);
assert.property(TestModel,'find');
assert.isFalse(TestModel.is_table_ready());
done();
});
})
});

describe('Validation >', function(){

it('field validation', function(){
Expand Down