Skip to content

In apos-global, joinByOne in an object is not resolved in Live mode. (underlying id not updated to point to Live ver when commit) #283

@ericwong3

Description

@ericwong3

In apostrophe-global, when there is an object field containing a joinByOne field, the relationship is not resolved as expected when in Live mode, the field will be missing completely (and the ID field will retain draft version's ID).

Steps to Reproduce

  1. Start an empty project with apostrophe cli and npm i inside
  2. cd into the new project and do npm install --save apostrophe-workflow
  3. Add the default snippet
'apostrophe-workflow': {
  // IMPORTANT: if you follow the examples below,
  // be sure to set this so the templates work
  alias: 'workflow',
  // Recommended to save database space. You can still
  // export explicitly between locales
  replicateAcrossLocales: false
},
'apostrophe-workflow-modified-documents': {}
  1. Create lib/modules/apostrophe-global/index.js with the following content:
module.exports = {
  addFields: [
    {
      name: 'demoField',
      label: 'Demo Field',
      type: 'object',
      schema: [{
        "type": "joinByOne",
        "required": true,
        "name": "_demoFieldInner",
        "label": "Demo Field Inner",
        "withType": "apostrophe-page",
      }],
    },
    
    {
      "type": "joinByOne",
      "required": true,
      "name": "_demoField2",
      "label": "Demo Field 2",
      "withType": "apostrophe-page",
    }
  ]
}
  1. In lib/modules/apostrophe-pages/views/pages/home.html, add <script>console.log({{ data.global|json }})</script> for testing.
  2. Start the app, login as admin, edit Global, for both field pick Home itself, then save draft, open Global again, commit.
  3. In Draft mode, observe in terminal that demoField2Id, _demoField2, demoField.demoFieldInnerId, demoField._demoFieldInner are all present as expected:
    image
  4. Switch to Live mode, observe in terminal that demoField2Id, _demoField2, and demoField.demoFieldInnerId are present, but demoField._demoFieldInner is not. Moreover, the ID in demoField.demoFieldInnerId is still storing draft version's ID (maybe hinting the commit flow is forgetting to update this ID to point to the Live home page's ID):
    image

Notes
The field setup should be valid, this works perfectly fine before workflow module is installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions