Hi,

I have a content type called "subject" that has nodes attached to it (from a "contribution" content type) using the entity reference module. On the front page of my site I want to show a list of the "subject" nodes. This is easy enough but how can I also display a field from the "contribution" nodes attached to it? So for example if I had a view to display the title of 3 "subjects" along with a "contribution" field it might look like this:

Subject Title 1
Field from contribution 1

Subject Title 2
Field from contribution 2

Subject Title 3
Field from contribution 3

I'd really appreciate any help, I can't seem to get my head around how to do this.

Files: 
CommentFileSizeAuthor
#6 ss.png81.81 KBJboo
#6 ss2.png81.52 KBJboo
#5 delta.PNG21.13 KBcasaran

Comments

Hi Jboo,

- First, you have to give a relationship in your view. Choose the entity reference field you are using to reference "contribution" nodes.
- Then add fields corresponding to existing fields in "contribution", but when you add them, say that yes you want them to use the relationship you just added.

You should get a result similar to your example.

Hi Casaran,

Thanks for your reply, it's much appreciated. I seem to be getting somewhere but I'm stuck on something! I can show the "subject" title along with a field from the "contribution" attached to the subject node, but it's repeating the "subject" several times if there are many "contributions" attached. For example if I have 2 subjects; subject 1 has 3 contributions attached and subject 2 has 4 contributions attached then my view is shown like this...

Subject Title 1
Field from contribution 1

Subject Title 1
Field from contribution 2

Subject Title 1
Field from contribution 3

Subject Title 2
Field from contribution 4

Subject Title 2
Field from contribution 5

Subject Title 2
Field from contribution 6

Subject Title 2
Field from contribution 7

What I'm aiming to do is have an 1 subject entry along with 1 contribution. (Ideally, as the contribution has a 'flag' so users can vote for the node, I'd like to show the field from the node with the highest flag count). Let's say I have 4 "subjects" each with several "contributions" attached, what I'm aiming for is this:

Subject Title 1
Field from most flagged 'contribution' node attached to "Subject Title 1"

Subject Title 2
Field from most flagged 'contribution' node attached to "Subject Title 2"

Subject Title 3
Field from most flagged 'contribution' node attached to "Subject Title 3"

Subject Title 4
Field from most flagged 'contribution' node attached to "Subject Title 4"

Sorry if this is getting complicated! I'd love to get this to work and any help would be great.

Thanks again.

Right right, my answer wasn't totally complete, sorry about that.

First of all, in your relationship, you can select "Require this relationship" if you want Subjects without any contribution to not appear.

Now for your problem, I think the best solution is like this:
- In sort criteria, sort by the highest flag count descending while saying you are using your relationship. This will sort your view by the contribution flag count for each different node of type Subject.
- Now go in your relationship and in the field "delta" select "1". This will only take the first node of each type, meaning since they are sorted by flag count, it will only display the one with the highest flag count.

This should normally do it.

I can see how this would work but I don't seem to have the options to change those settings. The problems I'm having are...

- In sort criteria, sort by the highest flag count descending while saying you are using your relationship. This will sort your view by the contribution flag count for each different node of type Subject.
I can't seem to choose the relationship in the flag count sort criteria, because I'm already using a relationship of 'flag-counter' to get the flag count.

- Now go in your relationship and in the field "delta" select "1". This will only take the first node of each type, meaning since they are sorted by flag count, it will only display the one with the highest flag count.
I can't find this option in my relationship.

Do you do paid work Casaran? I noticed on your profile you provide Drupal related services and if I can provide you the login details to my site and it's not too difficult I'd be happy to pay you for your time to sort this for me. If not, no worries, I'll play around until I managed to get this to work.

Thanks again.

StatusFileSize
new21.13 KB

Well I don't mind continuing to help you here until we arrive to a solution. If you really believe you will not be able to do it, then PM me, but I advise you against saying (and doing) things like providing login information to strangers.

So you are telling me you don't have something like in the image I attached? I am using Reference module and not Entity Reference module but I thought both had something like that. If not then try using Reference module.

For the other problem, it is a bit tricky now. One solution would be to sort your view using Views PHP module. You will get your flag count from a custom php field, which will be used in sort criteria.
Another possibility would be to make one relationship use the second one and say your field use the first one, so your field would use both relationship this way. I am not too sure about this solution but try it first because it's the simpliest one.

StatusFileSize
new81.52 KB
new81.81 KB

Hi,

I've posted a screenshot of what my relationship setting looks like. It'd be difficult to change from the Entity Reference module because a lot of the site depends on it at the moment. The second problem is that I don't seem to have the option to make one relationship use the second one. I've attached another image to show what I mean.

I didn't think it would be so difficult to get this working! Hopefully I'll get there in the end though.

Thanks again.

I understand. It seems the delta was not implemented in Entity Reference module while it is in References module. Fortunately, there seems to be a patch for it:
https://drupal.org/node/1468862#comment-6449450
Please try to apply it.

Now as said in https://drupal.org/node/1292402#comment-5048224, there is nothing in Entity Reference module to link a field to several relationships and it's not possible either to make a relation use another. So I guess you will have to go with something like Views PHP module or some custom code (perhaps hooks of the view).

Hope it helps (too bad you're not using References module).