I have content types of ‘Region’ and ‘City’. Each Region node has a node reference to multiple City nodes.
Region1 has a reference to CityA and CityB.
Region2 has a reference to CityC and CityD
Im trying to make a View like this;
Region1
Region1 Description
CityA
CityB
Region2
Region2 Description
CityC
CityD
Ive created a View of node type Regions, and added the Description Field;
Region1
Region1 Description
Region2
Region2 Description
The problems starts when I add a Relationship. Ive added a Relationship of my node reference and added a Node Title Field which uses this Relationship. This causes the following;
Region1
Region1 Description
CityA
Region1
Region1 Description
CityB
Region2
Region2 Description
CityC
Region2
Region2 Description
CityD
How can I stop the Region’s Title and Description being duplicated for every additional City it relates to?
Thanks
Comments
Comment #1
dawehnerI don't see the problem. You have mutliple references, so multiple get's returned
To fix this you could use the group features of styles.
Comment #2
jdln commentedOK. Ive got this working. I thought id share my solution, although their may be a more elegant way of doing it.
I understand why this is happening from the perspective of how Drupal 'thinks', but I want this;
Region1
Region1 Description
CityA
CityB
Region2
Region2 Description
CityC
CityD
And instead I have this;
Region1
Region1 Description
CityA
Region1
Region1 Description
CityB
Region2
Region2 Description
CityC
Region2
Region2 Description
CityD
If I set the Group Field to Node: Title (for Region), I get this;
Region1
Region1
Region1 descrption
CityA
Region1
Region1 descrption
CityB
Region2
Region2
Region2 Descprtion
CityC
Region2
Region2 Descprtion
CityD
The only solution ive found is to exclude the Node Title (for Region) and Body from displaying, group by the Node Title (for Region), and rewrite the Node Title (for Region) output to include the Body.
This works but everything in the group title is wrapped in h3 tags. To stop this I removed the h3 tags from views-view-unformatted.tpl.php.
Thanks
Comment #3
jdln commentedOoops. I dont know how I made this mistake but my method doesn't work. Can this be solved with the grouping style somehow?
The fix im using for my site is to change the display from fields to node teasers. Ive then embedded a view in my node teaser with my template files. Effectively ive made a view within a view. It would be great if there was an easier way.
Comment #4
jdln commentedIve been playing around with this for a while now. The method from #2 works for one site and not for another.
For that site that works their is a node reference of a node reference. As far as I can tell this is the only difference but I dont know why this is making it work.
Comment #5
jdln commentedIve done some more experimenting. It seems some fields can be entered in the 'Rewrite the output of this field' section and work as I want them to, and others create the problem ive been talking about.
For one site im using ubercart fileds. Ive added sell_price and addtocartlink_1 fields. Neither use a relationship and both are hidden from display.
Im grouping by Node title, which ive hidden from display and im rewriting its output. If I add [sell_price] everything is ok but if I add [addtocartlink_1] then everything else in this rewritten display appears multiple times.
Im guessing this is to do with how the fields are stored in the database. Is the themed view within a view the only surefire solution?
Thanks
Comment #6
dawehnerCan you name me a way to achive this with sql? I guess no
Comment #7
jdln commentedIm afraid I dont know much about sql, sorry.
Comment #8
merlinofchaos commentedHaving multiple additional pieces of data associated with a piece of data causes multiple rows in SQL. That's one of the core truths of SQL and since Views is a SQL engine, Views will do that.
When you use a relationship, you are going to get one record per related node. To wit:
I have node type A and node type B. Node type A contains a reference (that can have multiple values) to type B.
When I make a list of node type A, and add the relationship to B, then I will get one 'copy' of node type A for every type B I have.
If you want to somehow filter on node type B while listing just a single instance of node type A, you have very few options. Views 3 will allow you to do some amount of GROUP BY stuff, but in general the answer is "IN SQL, it's complicated" so things don't necessarily work the way we want them to.
When using multiple fields on a single node, that field will usually have a "group multiple" checkbox that will allow you to avoid this. It accomplishes this by not actually including that field in the query, but by retrieving the information in a secondary query. This is why you can't just get arbitrary data from multiple related nodes; there's really no way to do that. The nodereference field allows you to group titles and that is just about it.
Comment #9
jdln commentedOK, Thanks.
Comment #10
jmary commentedI found a pretty solution to avoid this problem. It needs to create another view and make use of the views_field_view module.
This is more CPU consuming, but open also another wide range of possibilities. My initial problem was to display the schedule of sessions at an event where several speakers at one session would trigger the display of the sessions several times.
Comment #11
debo7debo commentedDid this feature come in views3 as you said? I am also having the same problem and would like a solution. Even I could get to separate the related contentB by comma would be good.
Comment #12
merlinofchaos commentedviews_view_field module might serve your purpose.