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.
apostrophe-cms
add a comment |
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.
apostrophe-cms
add a comment |
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.
apostrophe-cms
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
apostrophe-cms
asked Nov 7 at 12:39
Fawzi
236110
236110
add a comment |
add a comment |
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
add a comment |
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.
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Nov 10 at 15:38
answered Nov 10 at 15:29
Stuart Romanek
1,240127
1,240127
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 19 at 19:09
Tom Boutell
4,14611916
4,14611916
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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