Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ericwong3 opened this issue Nov 5, 2019 · 4 comments
Labels

Comments

@ericwong3
Copy link

ericwong3 commented Nov 5, 2019

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.

@ericwong3
Copy link
Author

any updates :(

@ericwong3
Copy link
Author

I dug into the core and applied this patch, apparently does the trick:

diff --git a/node_modules/apostrophe-workflow/lib/implementation.js b/node_modules/apostrophe-workflow/lib/implementation.js
index 22be6fc..1a6d573 100644
--- a/node_modules/apostrophe-workflow/lib/implementation.js
+++ b/node_modules/apostrophe-workflow/lib/implementation.js
@@ -348,6 +348,9 @@ module.exports = function(self, options) {
               fromArrays = fromArrays.concat(self.findJoinsInSchema(doc, field.schema));
             });
           }
+          if (field.type === 'object' && typeof doc[field.name] === 'object') {
+            fromArrays = fromArrays.concat(self.findJoinsInSchema(doc[field.name], field.schema));
+          }
         }
       ), function(field) {
         return { doc: doc, field: field, value: doc[field.name] };

@boutell
Copy link
Contributor

boutell commented Nov 18, 2019 via email

@stale
Copy link

stale bot commented Jun 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 19, 2020
@abea abea added the bug label Jun 22, 2020
@stale stale bot removed the stale label Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants