Replies: 7 comments 4 replies
-
In case it might help someone, I have a solution that works... but I'd love to hear from one of the Orchard experts as I expect I'm not doing this the ideal way. In any event, what I did is create a UserCoursePart index and index provider that makes UserId, Course ContentItemId, and Status easily available and queryable. I then created a class loosely based on SqlQuerySource that allows me to execute a raw SQL query. I can then do my left join on ContentItemIndex where ContentType is Course and the UserCoursePartIndex table joining on its CourseContentItemId with ContentItemIndex's ContentItemId. I also join in the Document table twice based on each index's DocumentId field and return the Document.Content field for both the Course and UserCourse. Finally when those two fields come back, I use the content serializer from the I'm not sure if this is crazy or the right thing to do (or somewhere in between). I'm going to try it out for a while and see if I run into any issues. In the meantime, hopefully one of the experts will weigh in. |
Beta Was this translation helpful? Give feedback.
-
Normally you don't need to use the serializer if content items (parts/fields) are correctly loaded by the content manager and then activated. We have extension helpers to still use Then there are YesSql helpers to do more complex queries joining on more than one index table, we have e.g. Okay, this one |
Beta Was this translation helpful? Give feedback.
-
If perf is a concern you have to check, sometimes better to use 2 simple queries in place of a too complex one implying multiple joins. In that case you can do first a direct You can also cache relations, not full items but related Ids, the cache being populated from the index table on startup and invalidation (e.g. through an handler on saving). We have services and helpers for this but that's another story ;) |
Beta Was this translation helpful? Give feedback.
-
Looks like we posted at the same time... so not sure you saw my last one. Perf is definitely a concern. One clarification to my previous post - I want the 100 Courses and the 5 UserCourses in one query and that query should have 100 total result records. E.g. it has two fields: "Course" and "UserCourse," and "UserCourse" is null 95 of the 100 times but all 100 have a non-null Course. I had a way to do this with multiple queries and I was stiching the objects together (setting a User.UserCourse property) but it seemed very hacky. I think in this case it is just three simple joins - I'm not a SQL expert but have always preferred some basic joins over multiple queries. Maybe I'm totally misunderstanding the way to implement related content items that have many to many relationship. |
Beta Was this translation helpful? Give feedback.
-
Okay would need to look at it more in details. Hmm, to return 2 types of items you may need to still use ContentItemIndex and 2 other IndexTable1 and IndexTable2, both having a DocumentId column as we do in the source code in many places, maybe something like this.
|
Beta Was this translation helpful? Give feedback.
-
This was my original thinking but, after doing a bunch of YesSql reading and poking around the source, it seemed like |
Beta Was this translation helpful? Give feedback.
-
Thanks for the link, it is definitely helpful in understanding this better, and it does seem to be getting to the join functionality I'm looking for, but I don't see how it returns content from both the main content item from ContentItemIndex and another content item from another index. On the line above the one you reference in the link, line 33, it has a comment for the generic type parameter T: "The type to return. It can be and index or an entity." This again seems to confirm all of these methods are designed to return a single content item object. And in looking at the tokes query you reference:
...it seems to be returning just the single TToken type as a list of token objects (even though it used multiple indexes to get the desired tokens). Are there any examples that return two related content items deserialized from document table's Content field as a single record? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to model a school where users can take courses. I created Course and UserCourse content types. Course has a name and description. UserCourse has a user (using UserPickerFeld), a course (using ContentPickerField), and a status (using an enum stored on UserCoursePart). So the JSON looks like this:
I can query for all Course content types using YesSql's ISession with something like this:
var contentItems = await _session.Query<ContentItem, ContentItemIndex>(index => index.ContentType == "Course").ListAsync();
...but is there any way related UserCourse content items for the current user can be included with the Course content items? I need it to return all Courses even if there is no UserCourse (e.g. a SQL left join on Course and UserCourse) so I can show a list of all courses with status indicators on those the current user is taking.
Beta Was this translation helpful? Give feedback.
All reactions