Merge branch 'feat/db-adapters' of github.com:payloadcms/payload into feat/db-adapters
This commit is contained in:
@@ -37,6 +37,8 @@ export interface Args {
|
||||
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
|
||||
useFacet?: boolean;
|
||||
};
|
||||
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
||||
autoPluralization?: boolean;
|
||||
}
|
||||
|
||||
export type MongooseAdapter = DatabaseAdapter &
|
||||
@@ -59,6 +61,7 @@ export function mongooseAdapter({
|
||||
url,
|
||||
connectOptions,
|
||||
migrationDir,
|
||||
autoPluralization = true,
|
||||
}: Args): MongooseAdapterResult {
|
||||
function adapter({ payload }: { payload: Payload }) {
|
||||
mongoose.set('strictQuery', false);
|
||||
@@ -71,6 +74,7 @@ export function mongooseAdapter({
|
||||
sessions: {},
|
||||
url,
|
||||
connectOptions: connectOptions || {},
|
||||
autoPluralization,
|
||||
globals: undefined,
|
||||
collections: {},
|
||||
versions: {},
|
||||
|
||||
@@ -69,12 +69,17 @@ export const init: Init = async function init(
|
||||
const model = mongoose.model(
|
||||
versionModelName,
|
||||
versionSchema,
|
||||
versionModelName,
|
||||
) as CollectionModel;
|
||||
// this.payload.versions[collection.slug] = model;
|
||||
this.versions[collection.slug] = model;
|
||||
}
|
||||
|
||||
const model = mongoose.model(collection.slug, schema) as CollectionModel;
|
||||
const model = mongoose.model(
|
||||
collection.slug,
|
||||
schema,
|
||||
this.autoPluralization === true ? undefined : collection.slug,
|
||||
) as CollectionModel;
|
||||
this.collections[collection.slug] = model;
|
||||
|
||||
// TS expect error only needed until we launch 2.0.0
|
||||
@@ -116,6 +121,7 @@ export const init: Init = async function init(
|
||||
const versionsModel = mongoose.model(
|
||||
versionModelName,
|
||||
versionSchema,
|
||||
versionModelName,
|
||||
) as CollectionModel;
|
||||
this.versions[global.slug] = versionsModel;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export const buildGlobalModel = (config: SanitizedConfig): GlobalModel | null =>
|
||||
|
||||
globalsSchema.plugin(getBuildQueryPlugin());
|
||||
|
||||
const Globals = mongoose.model('globals', globalsSchema) as unknown as GlobalModel;
|
||||
const Globals = mongoose.model('globals', globalsSchema, 'globals') as unknown as GlobalModel;
|
||||
|
||||
Object.values(config.globals).forEach((globalConfig) => {
|
||||
const globalSchema = buildSchema(
|
||||
|
||||
Reference in New Issue
Block a user