使用 Breeze 元数据助手如何在客户端手动构造继承
Using Breeze metadata helper how to construct inheritance on client side by hand
使用 mongoose 和 Node.js 我制作了一个 Base 实体子分类为 User 实体和 Person 实体,并且都引用了 Family 实体,我的问题是使用 breeze-MetadataHelper 我如何定义一个家庭可以拥有 navigationProperties 数组,该数组采用 Person 或 User 实体。简而言之,我正在失去 OOP,所以有没有一种方法可以在客户端上使用 Breeze 构建具有多态支持的继承,这就是我想出的方法。
var addFamilyItemType = (): any => {
var entityType = {
name: this.entityNames.Family,
dataProperties: {
id: {type: DT.MongoObjectId},
name: {type: DT.String, required: true, max: 50}
},
navigationProperties: {
//this is where i want one navigation since they are a subclass
// members: {type: [], hasMany: true}
users: {type: [this.entityNames.User], hasMany: true},
people: {type: [this.entityNames.Person], hasMany: true}
}
};
helper.addTypeToStore(store, entityType);
return entityType;
};
var addUserItemType = (): any => {
var entityType = {
name: this.entityNames.User,
dataProperties: {
id: {type: DT.MongoObjectId},
email: {type: DT.String, required: true, max: 50},
username: {type: DT.String, required: true, max: 20},
password: {type: DT.String, 'default': ''}
},
navigationProperties: {
family: {
entityTypeName: this.entityNames.Family,
associationName: 'User_Family',
foreignKeyNames: ['familyId']
}
}
};
helper.addTypeToStore(store, entityType);
return entityType;
};
var addPersonItemType = (): any => {
var entityType = {
name: this.entityNames.Person,
dataProperties: {
id: {type: DT.MongoObjectId},
email: {type: DT.String, max: 50},
profileImageURL: {type: DT.String,'default':''}
},
navigationProperties: {
family: {
entityTypeName: this.entityNames.Family,
associationName: 'Person_Family',
foreignKeyNames: ['familyId']
}
}
};
helper.addTypeToStore(store, entityType);
return entityType;
};
我找到的解决方案是向 FamilyModel 对象添加一个 getter 属性 调用的成员,这将 return 在调用 registerEntityTypeCtor 时合并数组 User 和 Person,我想breeze 开箱即用地支持继承。
var metadataStore = this.metadata.createMetadataStore();
var registerType = metadataStore.registerEntityTypeCtor.bind(metadataStore);
registerType(this.metadata.entityNames.Family, FamilyModel);
使用 mongoose 和 Node.js 我制作了一个 Base 实体子分类为 User 实体和 Person 实体,并且都引用了 Family 实体,我的问题是使用 breeze-MetadataHelper 我如何定义一个家庭可以拥有 navigationProperties 数组,该数组采用 Person 或 User 实体。简而言之,我正在失去 OOP,所以有没有一种方法可以在客户端上使用 Breeze 构建具有多态支持的继承,这就是我想出的方法。
var addFamilyItemType = (): any => {
var entityType = {
name: this.entityNames.Family,
dataProperties: {
id: {type: DT.MongoObjectId},
name: {type: DT.String, required: true, max: 50}
},
navigationProperties: {
//this is where i want one navigation since they are a subclass
// members: {type: [], hasMany: true}
users: {type: [this.entityNames.User], hasMany: true},
people: {type: [this.entityNames.Person], hasMany: true}
}
};
helper.addTypeToStore(store, entityType);
return entityType;
};
var addUserItemType = (): any => {
var entityType = {
name: this.entityNames.User,
dataProperties: {
id: {type: DT.MongoObjectId},
email: {type: DT.String, required: true, max: 50},
username: {type: DT.String, required: true, max: 20},
password: {type: DT.String, 'default': ''}
},
navigationProperties: {
family: {
entityTypeName: this.entityNames.Family,
associationName: 'User_Family',
foreignKeyNames: ['familyId']
}
}
};
helper.addTypeToStore(store, entityType);
return entityType;
};
var addPersonItemType = (): any => {
var entityType = {
name: this.entityNames.Person,
dataProperties: {
id: {type: DT.MongoObjectId},
email: {type: DT.String, max: 50},
profileImageURL: {type: DT.String,'default':''}
},
navigationProperties: {
family: {
entityTypeName: this.entityNames.Family,
associationName: 'Person_Family',
foreignKeyNames: ['familyId']
}
}
};
helper.addTypeToStore(store, entityType);
return entityType;
};
我找到的解决方案是向 FamilyModel 对象添加一个 getter 属性 调用的成员,这将 return 在调用 registerEntityTypeCtor 时合并数组 User 和 Person,我想breeze 开箱即用地支持继承。
var metadataStore = this.metadata.createMetadataStore();
var registerType = metadataStore.registerEntityTypeCtor.bind(metadataStore);
registerType(this.metadata.entityNames.Family, FamilyModel);