Tag: 多态关联

带有mongoose和node.js的多态用户模型

我正在使用mean.js样板进行应用程序。 这是一个用户作为雇主和候选人的招聘引擎。 现在,雇主和候选人应该作为单独的文件存储,每个用户只能有一个雇主或候选人,因为每个候选人或雇主都需要用用户对象login。 我在rails中使用postgresql做到了这一点: ## User belongs_to :profileable, :polymorphic => true ## Candidate and Employer has_one :user, :as => :profileable 用mongoose,这是我迄今为止使用包“mongoose-schema-extend”所做的: var extend = require('mongoose-schema-extend'); var UserSchema = new Schema({ email: { type: String }, password: { type: String } }, { collection: 'users', discriminatorKey : '_type' }); var CandidateSchema = UserSchema.extend({ Experience: { type: […]