Is apostrophe-pieces-widgets paged ? or do i need to implement it manualy











up vote
0
down vote

favorite












I have a piece of properties, where each property is assigned to an agent,
what i'm trying to do, is show the list of properties assigned to each agent in it's "show" page.
i was thinking of using apostrophe-pieces-widgets inside the agent's page, but i'm not sure if it's feasible to use it that way, i need it to be paged.
if this is not the right way, i would to be pointed in the right direction.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a piece of properties, where each property is assigned to an agent,
    what i'm trying to do, is show the list of properties assigned to each agent in it's "show" page.
    i was thinking of using apostrophe-pieces-widgets inside the agent's page, but i'm not sure if it's feasible to use it that way, i need it to be paged.
    if this is not the right way, i would to be pointed in the right direction.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a piece of properties, where each property is assigned to an agent,
      what i'm trying to do, is show the list of properties assigned to each agent in it's "show" page.
      i was thinking of using apostrophe-pieces-widgets inside the agent's page, but i'm not sure if it's feasible to use it that way, i need it to be paged.
      if this is not the right way, i would to be pointed in the right direction.










      share|improve this question













      I have a piece of properties, where each property is assigned to an agent,
      what i'm trying to do, is show the list of properties assigned to each agent in it's "show" page.
      i was thinking of using apostrophe-pieces-widgets inside the agent's page, but i'm not sure if it's feasible to use it that way, i need it to be paged.
      if this is not the right way, i would to be pointed in the right direction.







      apostrophe-cms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 12:39









      Fawzi

      236110




      236110
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Edit: Just seeing your note about needing it to be paged, do you mean paginated? If so the answer would be bit more involved



          The below answer would get all joined property pieces and pass them to the agent show page



          Assuming when you say 'each property is assigned to an agent' you mean that each property has a joinByOne field pointing at an agent piece, you can get all the related docs in the beforeShow method of your agent-pages module and attach them to data so they are available in your template (/lib/modules/AGENT-PAGES-MODULE/views/show.html)



          in /lib/modules/AGENT-PAGES-MODULE/index.js



          ```



          module.exports = {
          ... basic module configuration
          construct: function (self, options) {
          self.beforeShow = function(req, callback) {
          var criteria = { idFIELD_NAME_IN_PROPERTY_SCHEMA: req.data.piece._id }
          var projection = {} // This will get entire matching doc, you should clamp this down
          return self.apos.modules['PROPERTY_MODULE_NAME'].find(req, criteria, projection).toArray(function (err, docs) {
          req.data.relatedDocs = docs
          return callback(null);
          });
          }
          }
          };


          ```



          Then in show.html you will have data.relatedDocs to iterate over






          share|improve this answer






























            up vote
            1
            down vote













            Without pagination in the picture, the easiest way is to add a reverse join.



            If properties have this field:



            {
            name: '_agents',
            type: 'joinByArray',
            withType: 'agent'
            }


            Then agents can have this one to get a list of properties that join to them, as the _properties field:



            {
            name: '_properties',
            type: 'joinByArrayReverse',
            reverseOf: '_agents'
            }


            With pagination in the picture, it depends. If we're talking about perhaps 100 properties per agent, I would say to use this technique and optionally implement pagination yourself at the template level. If there are more than 100 properties per agent, it might become worthwhile to implement your own query for the properties, setting perPage() on that cursor and using toCount() to get the count, then repeating the query with toArray() using perPage() and page() to specify a page number. Which is exactly what apostrophe-pieces-pages does to implement pagination, so you can borrow from there.



            Long term it would be more ideal if pagination could be specified through configuration for joins and reverse joins in Apostrophe.






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189659%2fis-apostrophe-pieces-widgets-paged-or-do-i-need-to-implement-it-manualy%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote



              accepted










              Edit: Just seeing your note about needing it to be paged, do you mean paginated? If so the answer would be bit more involved



              The below answer would get all joined property pieces and pass them to the agent show page



              Assuming when you say 'each property is assigned to an agent' you mean that each property has a joinByOne field pointing at an agent piece, you can get all the related docs in the beforeShow method of your agent-pages module and attach them to data so they are available in your template (/lib/modules/AGENT-PAGES-MODULE/views/show.html)



              in /lib/modules/AGENT-PAGES-MODULE/index.js



              ```



              module.exports = {
              ... basic module configuration
              construct: function (self, options) {
              self.beforeShow = function(req, callback) {
              var criteria = { idFIELD_NAME_IN_PROPERTY_SCHEMA: req.data.piece._id }
              var projection = {} // This will get entire matching doc, you should clamp this down
              return self.apos.modules['PROPERTY_MODULE_NAME'].find(req, criteria, projection).toArray(function (err, docs) {
              req.data.relatedDocs = docs
              return callback(null);
              });
              }
              }
              };


              ```



              Then in show.html you will have data.relatedDocs to iterate over






              share|improve this answer



























                up vote
                0
                down vote



                accepted










                Edit: Just seeing your note about needing it to be paged, do you mean paginated? If so the answer would be bit more involved



                The below answer would get all joined property pieces and pass them to the agent show page



                Assuming when you say 'each property is assigned to an agent' you mean that each property has a joinByOne field pointing at an agent piece, you can get all the related docs in the beforeShow method of your agent-pages module and attach them to data so they are available in your template (/lib/modules/AGENT-PAGES-MODULE/views/show.html)



                in /lib/modules/AGENT-PAGES-MODULE/index.js



                ```



                module.exports = {
                ... basic module configuration
                construct: function (self, options) {
                self.beforeShow = function(req, callback) {
                var criteria = { idFIELD_NAME_IN_PROPERTY_SCHEMA: req.data.piece._id }
                var projection = {} // This will get entire matching doc, you should clamp this down
                return self.apos.modules['PROPERTY_MODULE_NAME'].find(req, criteria, projection).toArray(function (err, docs) {
                req.data.relatedDocs = docs
                return callback(null);
                });
                }
                }
                };


                ```



                Then in show.html you will have data.relatedDocs to iterate over






                share|improve this answer

























                  up vote
                  0
                  down vote



                  accepted







                  up vote
                  0
                  down vote



                  accepted






                  Edit: Just seeing your note about needing it to be paged, do you mean paginated? If so the answer would be bit more involved



                  The below answer would get all joined property pieces and pass them to the agent show page



                  Assuming when you say 'each property is assigned to an agent' you mean that each property has a joinByOne field pointing at an agent piece, you can get all the related docs in the beforeShow method of your agent-pages module and attach them to data so they are available in your template (/lib/modules/AGENT-PAGES-MODULE/views/show.html)



                  in /lib/modules/AGENT-PAGES-MODULE/index.js



                  ```



                  module.exports = {
                  ... basic module configuration
                  construct: function (self, options) {
                  self.beforeShow = function(req, callback) {
                  var criteria = { idFIELD_NAME_IN_PROPERTY_SCHEMA: req.data.piece._id }
                  var projection = {} // This will get entire matching doc, you should clamp this down
                  return self.apos.modules['PROPERTY_MODULE_NAME'].find(req, criteria, projection).toArray(function (err, docs) {
                  req.data.relatedDocs = docs
                  return callback(null);
                  });
                  }
                  }
                  };


                  ```



                  Then in show.html you will have data.relatedDocs to iterate over






                  share|improve this answer














                  Edit: Just seeing your note about needing it to be paged, do you mean paginated? If so the answer would be bit more involved



                  The below answer would get all joined property pieces and pass them to the agent show page



                  Assuming when you say 'each property is assigned to an agent' you mean that each property has a joinByOne field pointing at an agent piece, you can get all the related docs in the beforeShow method of your agent-pages module and attach them to data so they are available in your template (/lib/modules/AGENT-PAGES-MODULE/views/show.html)



                  in /lib/modules/AGENT-PAGES-MODULE/index.js



                  ```



                  module.exports = {
                  ... basic module configuration
                  construct: function (self, options) {
                  self.beforeShow = function(req, callback) {
                  var criteria = { idFIELD_NAME_IN_PROPERTY_SCHEMA: req.data.piece._id }
                  var projection = {} // This will get entire matching doc, you should clamp this down
                  return self.apos.modules['PROPERTY_MODULE_NAME'].find(req, criteria, projection).toArray(function (err, docs) {
                  req.data.relatedDocs = docs
                  return callback(null);
                  });
                  }
                  }
                  };


                  ```



                  Then in show.html you will have data.relatedDocs to iterate over







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 10 at 15:38

























                  answered Nov 10 at 15:29









                  Stuart Romanek

                  1,240127




                  1,240127
























                      up vote
                      1
                      down vote













                      Without pagination in the picture, the easiest way is to add a reverse join.



                      If properties have this field:



                      {
                      name: '_agents',
                      type: 'joinByArray',
                      withType: 'agent'
                      }


                      Then agents can have this one to get a list of properties that join to them, as the _properties field:



                      {
                      name: '_properties',
                      type: 'joinByArrayReverse',
                      reverseOf: '_agents'
                      }


                      With pagination in the picture, it depends. If we're talking about perhaps 100 properties per agent, I would say to use this technique and optionally implement pagination yourself at the template level. If there are more than 100 properties per agent, it might become worthwhile to implement your own query for the properties, setting perPage() on that cursor and using toCount() to get the count, then repeating the query with toArray() using perPage() and page() to specify a page number. Which is exactly what apostrophe-pieces-pages does to implement pagination, so you can borrow from there.



                      Long term it would be more ideal if pagination could be specified through configuration for joins and reverse joins in Apostrophe.






                      share|improve this answer

























                        up vote
                        1
                        down vote













                        Without pagination in the picture, the easiest way is to add a reverse join.



                        If properties have this field:



                        {
                        name: '_agents',
                        type: 'joinByArray',
                        withType: 'agent'
                        }


                        Then agents can have this one to get a list of properties that join to them, as the _properties field:



                        {
                        name: '_properties',
                        type: 'joinByArrayReverse',
                        reverseOf: '_agents'
                        }


                        With pagination in the picture, it depends. If we're talking about perhaps 100 properties per agent, I would say to use this technique and optionally implement pagination yourself at the template level. If there are more than 100 properties per agent, it might become worthwhile to implement your own query for the properties, setting perPage() on that cursor and using toCount() to get the count, then repeating the query with toArray() using perPage() and page() to specify a page number. Which is exactly what apostrophe-pieces-pages does to implement pagination, so you can borrow from there.



                        Long term it would be more ideal if pagination could be specified through configuration for joins and reverse joins in Apostrophe.






                        share|improve this answer























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          Without pagination in the picture, the easiest way is to add a reverse join.



                          If properties have this field:



                          {
                          name: '_agents',
                          type: 'joinByArray',
                          withType: 'agent'
                          }


                          Then agents can have this one to get a list of properties that join to them, as the _properties field:



                          {
                          name: '_properties',
                          type: 'joinByArrayReverse',
                          reverseOf: '_agents'
                          }


                          With pagination in the picture, it depends. If we're talking about perhaps 100 properties per agent, I would say to use this technique and optionally implement pagination yourself at the template level. If there are more than 100 properties per agent, it might become worthwhile to implement your own query for the properties, setting perPage() on that cursor and using toCount() to get the count, then repeating the query with toArray() using perPage() and page() to specify a page number. Which is exactly what apostrophe-pieces-pages does to implement pagination, so you can borrow from there.



                          Long term it would be more ideal if pagination could be specified through configuration for joins and reverse joins in Apostrophe.






                          share|improve this answer












                          Without pagination in the picture, the easiest way is to add a reverse join.



                          If properties have this field:



                          {
                          name: '_agents',
                          type: 'joinByArray',
                          withType: 'agent'
                          }


                          Then agents can have this one to get a list of properties that join to them, as the _properties field:



                          {
                          name: '_properties',
                          type: 'joinByArrayReverse',
                          reverseOf: '_agents'
                          }


                          With pagination in the picture, it depends. If we're talking about perhaps 100 properties per agent, I would say to use this technique and optionally implement pagination yourself at the template level. If there are more than 100 properties per agent, it might become worthwhile to implement your own query for the properties, setting perPage() on that cursor and using toCount() to get the count, then repeating the query with toArray() using perPage() and page() to specify a page number. Which is exactly what apostrophe-pieces-pages does to implement pagination, so you can borrow from there.



                          Long term it would be more ideal if pagination could be specified through configuration for joins and reverse joins in Apostrophe.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 19 at 19:09









                          Tom Boutell

                          4,14611916




                          4,14611916






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189659%2fis-apostrophe-pieces-widgets-paged-or-do-i-need-to-implement-it-manualy%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Costa Masnaga

                              Fotorealismo

                              Sidney Franklin