best way to find child content? Author to books example
Please consider the following:
I have book document type .
I have author document type.
On my book document Type I have a multinode tree picker that is setup to choose the correct author node id.
This results in a content object that looks like the following:
When I render my template I convert nodeId 1246 back to content and then present the underlying values. Works great!
My problem now is that i want to represent all the books the author is attributed to on the 1246 node.
Can someone explain how I would go about finding all the books that are now assigned to that author? I am pretty sure this has been asked before but I can't find any reasonable examples.
Thanks for any assistance.
Brads mechanism would work fairly well. However, I would also look into the relationships api as this is a great use for it.
If you hook into the save event you can establish a relationship between author and books then simply query the relationship api with the author to get all of the books they are linked to.
Hi. I am just looking into the relations API but set up the examine index based on the article Using Examine. I set it up fairly quickly but don't really see how or why your would override the save method.
Essentially we setup an index on our articles to only index the author userfield (nodeid list). After that it was dead simple to get the IPublishedContent back.
Pleased to hear you got it working. The reason you may need to hook into the save event is that if any of your properties store information as a comma separated list you need to remove the commas else lucene/examine won't return the correct results.
Hi Nik.
Two questions.
1: Are you saying that if I used the tag editor for example and then setup a tagIndexSearch on that user field the lucene wouldn't work correctly?
The tags property produces just a comma separated list currently.
2: know of any resources that talk about document to document relationships and doing exactly what you are talking about? I see a lot of member to document and they are not doing what we are talking about either.
Is the idea behind relationship api that only when documents are created/updated/saved at that point you create that relationship which in turn creates the row entry in the UmbracoRelation table for future lookup?
As for using relationships, you can create a relationship at any point in time I would have thought. However, if I was implementing your requirement I'd look at creating the relationship during the save event. I have to admit, it isn't something I've actually implemented myself but I believe the steps would be something along:
1) Create a relation type in the developer section
2) hook into the save event
3) using the Relations API, update/create/remove required relation entry.
I'm afraid I don't know of any resources demonstrating this off of the top of my head. Except for the one I was shown from the Level 2 course I did last year. If you haven't been on any of the Umbraco training I do highly recommend it :-)
That was my thoughts as well regarding the relationship steps as well. It could be messy however managing that with updates and deletes.
As far as training goes.. yes I would love to attend some training unfortunately no training days in North America until December 2016.
Thanks for your insights.
MM
best way to find child content? Author to books example
Please consider the following: I have book document type . I have author document type. On my book document Type I have a multinode tree picker that is setup to choose the correct author node id.
This results in a content object that looks like the following:
When I render my template I convert nodeId 1246 back to content and then present the underlying values. Works great!
My problem now is that i want to represent all the books the author is attributed to on the 1246 node. Can someone explain how I would go about finding all the books that are now assigned to that author? I am pretty sure this has been asked before but I can't find any reasonable examples. Thanks for any assistance.
I use examine. When saving I convert the id list from 1234, 1235 etc to 1234 1235 so lucene can search it. Then it's pretty simple lucene.
nodeTypeAlias:books authors:1234
Brads mechanism would work fairly well. However, I would also look into the relationships api as this is a great use for it.
If you hook into the save event you can establish a relationship between author and books then simply query the relationship api with the author to get all of the books they are linked to.
Hi. I am just looking into the relations API but set up the examine index based on the article Using Examine. I set it up fairly quickly but don't really see how or why your would override the save method.
Essentially we setup an index on our articles to only index the author userfield (nodeid list). After that it was dead simple to get the IPublishedContent back.
I am just reading up on the relationships API as well but this was a great step. I had no idea lucene was out of the box. Awesome.
Hi Mac,
Pleased to hear you got it working. The reason you may need to hook into the save event is that if any of your properties store information as a comma separated list you need to remove the commas else lucene/examine won't return the correct results.
It's just something to be aware of.
Nik
Hi Nik. Two questions. 1: Are you saying that if I used the tag editor for example and then setup a tagIndexSearch on that user field the lucene wouldn't work correctly? The tags property produces just a comma separated list currently.
2: know of any resources that talk about document to document relationships and doing exactly what you are talking about? I see a lot of member to document and they are not doing what we are talking about either. Is the idea behind relationship api that only when documents are created/updated/saved at that point you create that relationship which in turn creates the row entry in the UmbracoRelation table for future lookup?
I guess we need to look into how our documents are being saved? Would something like this suffice as a starting point? http://www.codeshare.co.uk/blog/intercepting-content-and-member-save-events-in-umbraco/ ? using version 7.4.3 Thanks mac
Hi Mac,
With regards to the tag editor, yes. That is what I'm saying. For some reason (I don't know exactly why) the query engine seems to struggle with ,'s.
It's a pretty simple fix you have to implement, but you'll need it for any properties that store information in that way.
This article here: http://shazwazza.com/post/searching-multi-node-tree-picker-data-or-any-collection-with-examine/ gives an example of how to go about resolving the issue but it's only a few lines of code to do the job.
As for using relationships, you can create a relationship at any point in time I would have thought. However, if I was implementing your requirement I'd look at creating the relationship during the save event. I have to admit, it isn't something I've actually implemented myself but I believe the steps would be something along:
1) Create a relation type in the developer section 2) hook into the save event 3) using the Relations API, update/create/remove required relation entry.
I'm afraid I don't know of any resources demonstrating this off of the top of my head. Except for the one I was shown from the Level 2 course I did last year. If you haven't been on any of the Umbraco training I do highly recommend it :-)
Nik
That was my thoughts as well regarding the relationship steps as well. It could be messy however managing that with updates and deletes. As far as training goes.. yes I would love to attend some training unfortunately no training days in North America until December 2016. Thanks for your insights. MM
is working on a reply...