File tree Expand file tree Collapse file tree
packages/db-mongodb/src/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change 155155 "test:eval:rest-api:low-power" : " cross-env EVAL_VARIANT=low-power NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 pnpm exec vitest --run --project eval eval.rest-api.spec" ,
156156 "test:eval:rest-api:skill" : " cross-env NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 pnpm exec vitest --run --project eval eval.rest-api.spec" ,
157157 "test:eval:skill" : " cross-env NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 vitest --run --project eval" ,
158- "test:int" : " cross-env NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 DISABLE_LOGGING=true vitest --project int" ,
158+ "test:int" : " cross-env NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 DISABLE_LOGGING=true vitest --project int --no-cache " ,
159159 "test:int:firestore" : " cross-env NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 PAYLOAD_DATABASE=firestore DISABLE_LOGGING=true vitest --project int" ,
160160 "test:int:postgres" : " cross-env NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 PAYLOAD_DATABASE=postgres DISABLE_LOGGING=true vitest --project int" ,
161161 "test:int:sqlite" : " cross-env NODE_OPTIONS=\" --no-deprecation --no-experimental-strip-types\" NODE_NO_WARNINGS=1 PAYLOAD_DATABASE=sqlite DISABLE_LOGGING=true vitest --project int" ,
Original file line number Diff line number Diff line change @@ -268,6 +268,10 @@ const blocks: FieldSchemaGenerator<BlocksField> = (
268268 }
269269
270270 block . fields . forEach ( ( blockField ) => {
271+ if ( fieldIsVirtual ( blockField ) ) {
272+ return
273+ }
274+
271275 const addFieldSchema = getSchemaGenerator ( blockField . type )
272276
273277 if ( addFieldSchema ) {
Original file line number Diff line number Diff line change @@ -832,6 +832,26 @@ export const getConfig: () => Partial<Config> = () => ({
832832 } ,
833833 ] ,
834834 } ,
835+ {
836+ name : 'blockWithVirtual' ,
837+ type : 'blocks' ,
838+ blocks : [
839+ {
840+ slug : 'blockWithVirtual' ,
841+ fields : [
842+ {
843+ name : 'text' ,
844+ type : 'text' ,
845+ } ,
846+ {
847+ name : 'virtualField' ,
848+ type : 'text' ,
849+ virtual : true ,
850+ } ,
851+ ] ,
852+ } ,
853+ ] ,
854+ } ,
835855 ] ,
836856 } ,
837857 {
Original file line number Diff line number Diff line change @@ -3290,6 +3290,32 @@ describe('database', () => {
32903290 expect ( res . textWithinTabs ) . toBeUndefined ( )
32913291 } )
32923292
3293+ it ( 'should not save a virtual field inside a block to the db' , async ( ) => {
3294+ const created = await payload . create ( {
3295+ collection : fieldsPersistanceSlug ,
3296+ data : {
3297+ blockWithVirtual : [
3298+ {
3299+ blockType : 'blockWithVirtual' ,
3300+ text : 'some text' ,
3301+ virtualField : 'should not be saved' ,
3302+ } ,
3303+ ] ,
3304+ } ,
3305+ } )
3306+
3307+ const resDb = ( await payload . db . findOne ( {
3308+ collection : fieldsPersistanceSlug ,
3309+ req : { } as PayloadRequest ,
3310+ where : { id : { equals : created . id } } ,
3311+ } ) ) as Record < string , unknown >
3312+
3313+ const block = ( resDb . blockWithVirtual as Record < string , unknown > [ ] ) ?. [ 0 ]
3314+
3315+ expect ( block ?. virtualField ) . toBeUndefined ( )
3316+ expect ( block ?. text ) . toBe ( 'some text' )
3317+ } )
3318+
32933319 it ( 'should allow virtual field with reference' , async ( ) => {
32943320 const post = await payload . create ( { collection : 'posts' , data : { title : 'my-title' } } )
32953321 const { id } = await payload . create ( {
You can’t perform that action at this time.
0 commit comments