【发布时间】:2015-10-16 13:09:30
【问题描述】:
我使用了流星、mongoDB 和自动表单。我的数据模型中有很多实体。 学院有一些学生和教师和班级。班级有一些学生和一名老师,每个学生都有一些成绩。
我设计了这个架构:
Schema = {};
Schema.UserProfile = new SimpleSchema({
name: {
type: String,
label: "Name"
},
family: {
type: String,
label: "Family"
},
address: {
type: String,
label: "Address",
optional: true,
max: 1000
},
workAddress: {
type: String,
label: "WorkAddress",
optional: true,
max: 1000
},
phoneNumber: {
type: Number,
label: "Phone Number",
optional: true
},
mobileNumber: {
type: Number,
label: "Phone Number"
},
birthday: {
type: Date,
optional: true
},
gender: {
type: String,
allowedValues: ['Male', 'Female'],
optional: true
},
description: {
type: String,
label: "Description",
optional: true,
max: 1000
}
});
Schema.User = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
emails: {
type: [Object],
// this must be optional if you also use other login services like facebook,
// but if you use only accounts-password, then it can be required
optional: true
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date,
optional: true
},
profile: {
type: Schema.UserProfile,
optional: true
},
// // Add `roles` to your schema if you use the meteor-roles package.
// // Option 1: Object type
// // If you specify that type as Object, you must also specify the
// // `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
// // Example:
// // Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
// // You can't mix and match adding with and without a group since
// // you will fail validation in some cases.
// roles: {
// type: Object,
// optional: true,
// blackbox: true
// }
// // Option 2: [String] type
// // If you are sure you will never need to use role groups, then
// // you can specify [String] as the type
roles: {
type: [String],
optional: true
}
});
//Meteor.users.attachSchema(Schema.User);
Schema.Grade: {
student: Schema.User,
class: Schema.Class,
gradeValue: value
}
Schema.Class: {
teacher: Schema.User,
students: {
type: [Schema.User]
},
grades: {
type: [Schema.Grade]
}
}
Schema.Academy: {
name: {
label: "academy name",
type: String
},
students: {
type: [Schema.User]
},
teachers: {
type: [Schema.User]
},
classes: {
type: [Schema.Class]
}
}
但我认为这不是最好的,也遇到过很多重复。
我需要以下查询:
academy classes
academy students
academy teachers
students classes
students grades
student profile
class students
class teacher
class grades
teacher students
teacher classes
teacher profile
【问题讨论】:
标签: mongodb meteor meteor-accounts meteor-autoform meteor-helper