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.
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