Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello. I have set up nuPickers for a test project and it seems great!
My test appliucation is following. I have Students and Classes. Students are linked/related to classes and i assume that classes will be automagically linked/related to the students right? how do i get these relations from my classes View? i have managed to get the relations from the Students view. So now i can see each classes that the students are taking, but is it possible to go to the Classes view and get all the students linked to this class? How do i do it? do i need to setup a property (i havent setup any property for this yet). how do i do this with code example?
In this example I create some content where I had X & Y nodes under a Z node, and I wanted to allow the user to pick an X that was related from the Y.
I created a relation in the Developers section under Relation types:
name: x2yalias: x2ydirection: Bidirectionalparent: Documentchild: Document
then in the data types added an editor
property editor: nuPickers:Xml Checkbox Pickerxml data: Contentxpath: //Z/X [@isDoc] //this is to only allow X nodes to be selected which are under the Z node in the rootrelation mapping: x2y //this is the one created abovesave format: Relations Only
added this property to my document type for Y and added some content which looks like this:
So then this is the bit I absolutely love about nuPickers, first I went round the houses looking at the various relations and relation service documentation and got nowhere for a while. nuPickers is excellently documented here https://github.com/uComponents/nuPickers/wiki/Property-Value-Converter you can see the that an extension is included that looks up and manages the picker data for you and gets you all the items in an easy to use list. So the template code I have for Y is very simple:
Layout = null;
<h1>A list of the Xs related to this Y</h1>
var pickedItems = CurrentPage.relation;
@foreach (var item in pickedItems.PickedKeys)
var x = @Umbraco.Content(item);
and so then we see the output looks like this:
However - I do see that from reading your question again - I think you had this part working. What you'd like to do is list it the other way around? As in listing all the Ys that picked this X on the "X" page. I'll take a look, I don't think this is supported by the helper in nuPickers but I'll take a look.
Exactly what you said in your last post John. I wanted to see how i can fetch it the other way around. The example you showed is well documented, and i managed to do that, its the other way around im interested in. Ill be eagerly waiting for your solution :)
Well I'm not totally happy with this answer, but with a lot of messing about I got to this:
Layout = null;
var relations = ApplicationContext.Services.RelationService.GetByParentId(CurrentPage.Id);
<h1>A list of the Ys that chose this X</h1>
@foreach (var r in relations)
if (r.RelationTypeId ==2)
var x = Umbraco.Content(r.ChildId);
The problems with this are that if there are no relations with that type ID you'll get an empty <UL> but if I add a query .where(r => r.RelationTypeId = 2) as shown documentation then I get an error "Cannot use a lambda expression as an argument to a dynamically dispatched operation" I'm not really sure what this means. Also was surprised by the fact that the one that chose is the child and the one selected is the parent, which seems backwards. Anyway this works at least... and I get this output:
Nice! can i ask what the if (r.RelationTypeId ==2) is? whats that 2? how robust is this way of doing it? does it require any kind of node structure or anything?
Actually, can you upload your code somewhere so i can look at it ?
>can i ask what the if (r.RelationTypeId ==2) is?
the relation type ID comes from here:
So it's the ID of the relation type we created, it doesn't feel outrageous to hard-code it as it is the specific relation type to the template you're building, you could possible get it by alias instead - so you could have something like:
int rtID = ApplicationContext.Services.RelationService.GetRelationTypeByAlias("x2y").Id;
In theory this is better, as if you transfer the site by courier the ID could change but the alias would stay the same. All this is only needed anyway if you have more than one relation type in use, you don't really need to filter it if you have only one. You could in theory also get the name of the relation type from the picker but the picker is on another page anyway so it would be another arbitrary lookup.
I really would much prefer to write something like:
var relations =ApplicationContext.Services.RelationService.GetByParentId(CurrentPage.Id).Where(r => r.RelationTypeId = 2);
but I don't understand why this gives me an error - I might ask a question in another thread about this and if I get an answer I'll post a link here.
If you had that then you could wrap the UL with something like
if (relations.Count >0)
which would be better, you could then maybe have an else that added a message like "this Y has been selected for no Xs" Linq is great for this sort of thing but I don't really understand why it doesn't work.
I'll upload my solution and put a link here in a bit for you.
I can't seem to access any filesharing services from behind the firewall here. If you send me an email to [email protected] then I can email a copy of the project to you.
nuPicker handles the relations under the hood, so you shouldn't need to go into the relations table. Simple use the nuPicker property value convertor retrieve values on both ends.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted