Related Content Query

Topics: Administration, Customizing Orchard, General
Nov 23, 2012 at 11:14 AM

I have two content types, Project and Task, both are simple content types made up of a title and body content part. What I want to do is create a query that will link the two content types together so that when viewing a project a projection widget on the page can be used to display all of the related tasks.

My initial attempt at achieving this was to add a content picker field to the Task content type and then creating a query filter with the following definition:

Task.Project is equal to '{Content.Id}'

Thinking that this would work I dropped the widget on the project page and voi...doh, nothing! I've since tried a number of different combinations of filter operators and values but I simply cannot get it to work. Can anyone point me in the right direction?

Thanks for your help.

Nov 26, 2012 at 10:08 PM

Looks like you're trying to match an id with a part.

Nov 27, 2012 at 9:42 AM

What I'm trying to do is display a list of related tasks when viewing a project, I assumed that the easiest way to do this would be to add a content picker to the Task content type so that when creating a new task you could specify the project and the creating a query that would return a list of tasks whose associated project id matches the current project (content.Id?) that could be added as a projection widget. If I'm not going about it the right way have you got any suggestions?

Nov 27, 2012 at 6:25 PM

Sure, that approach is fine, it's your projection that's not.

Nov 27, 2012 at 6:35 PM

Could you give me any pointers as to how I should structure the query so that it will work?

Nov 27, 2012 at 11:24 PM

You might want to compare ids to ids instead of ids to content items.

Nov 28, 2012 at 11:07 AM
Edited Nov 28, 2012 at 11:09 AM

That's what I'm trying to do, I basically want a query that says "give me all of the tasks whose related project id is equal to the current project id". When I try and create the filter for the query it allows me to specify the tasks project id field:

which I have then been setting to be equal to the {}:

which then gives me this filter:

I then add a projection widget to the site using this query hoping that when I view a project I will see a list of the related tasks. Unfortunately that's not the case as I'm posting here!


I'm obviously missing something obvious as you make it sound simple, do you know of a tutorial anywhere that goes through the process of how to do this as I've tried searching the forums and googling but to no avail?

Nov 28, 2012 at 11:02 PM

Try {{Content.Id}}

Nov 29, 2012 at 9:19 AM

I tried that but the query still returns no results, I also tried hard coding the value to 15 which is the id of the Project but that doesn't return any results either?

Nov 29, 2012 at 7:11 PM

To test with a hard-coded value it would have to be {15}. The content picker field gives the list of ids formatted with curly braces around. If that still doesn't work, you might want to create an issue in the issue tracker.

Nov 30, 2012 at 9:23 AM

I tried it with {15} and that didn't work either, if I gave you a log in to a test site where I've got it set up would you be able to check it out to make sure I'm not being an idiot before I submit an issue on the issue tracker?

Nov 30, 2012 at 5:22 PM

Please file a bug with repro steps then.

Dec 17, 2012 at 1:22 PM

Thanks Bertrand, I did some more playing about and found that with a hardcoded value of {{15}} it would work as expected but I could not get it working dynamically with the current Content Item Id. Have filed an issue here: