SPECIAL OFFER: Only $69 for access to everything in OSTraining for 1 year! You save $75!  2
Join today and get access to 1,000's of books and videos. Learn WordPress, Drupal, Magento, Joomla and more! Sign up today!

Views, references & contextual relationships

3 years 9 months ago #123845 by jwblock
New to Drupal and need help with Views. I think I understand the basic premise of how Drupal is supposed to work, but I'm having trouble getting the content to display correctly with relationships and contextual filters.

I have the following content types:
- Cruise Lines
- Cruise Ships
- Cabin Categories
- Sailings

Each of these content types has many fields.

There are many required "nested" views in the project, but I'll start with a simple one: I'd like the various fields in Cabin Categories to be displayed as a Block on the corresponding Cruise Ships page.

The fields that I would like to display in the block are: Cabin Category Name, Cabin Category Image, Cabin Category Size, Cabin Category Description for as many different Cabin Categories there are that belong to that Ship.

For example:
Cabin Category 1 NameCabin Category 1 ImageCabin Category 1 SizeCabin Category 1 Description
Cabin Category 2 NameCabin Category 2 ImageCabin Category 2 SizeCabin Category 2 Description
Cabin Category n NameCabin Category n ImageCabin Category n SizeCabin Category n Description

In a DB the key between the Ship and Cabin Category tables would be the Ship Name field. How do I set this up in Drupal?

The more I read about References and contextual filters to nodes, the more confused I become!

Here are the overall relationships of the data:
Cruise Lines
- Has multiple Cruise Ships
- No direct relationship to Cabin Categories (these are ship-specific)
- Has multiple Sailings

Cruise Ships
- Belongs to a single Cruise Line
- Has multiple Cabin Categories
- Has multiple Sailings

Cabin Categories
- Can belong to either a single Cruise Ship OR multiple Cruise Ships (e.g. "Cabin Category A" can be found in multiple Cruise Ships within a single Cruise Line AND on many different Cruise Lines)
- Not directly related to a Cruise Line, but to a Cruise Ship that is related to a Cruise Line
- Not directly related to a Sailing, but to a Cruise Ship that is related to a Sailing

Sailings
- Belongs to a single Cruise Line
- Belongs to a single Cruise Ship
- References the Cabin Categories that belong to the Cruise Ship of that Sailing

Please Log in to join the conversation.

3 years 9 months ago #123875 by steve
Hi and welcome, jwblock. We're really glad to have you with us.

That's a lot of detailed background information, although it really boils down to one question so far:

In a DB the key between the Ship and Cabin Category tables would be the Ship Name field. How do I set this up in Drupal?

The answer to that is you need a relationship to pull in the data in Views.

A Contextual Filter allows you to automatically update the view based on context. This class should help: www.ostraining.com/class/contextual-views/

A Relationship is allows you to use the DB key to pull in more details. For example, if you connect a node to it's author using a relationship, you'll then have access to all the other information from the author's profile.

Please Log in to join the conversation.

3 years 9 months ago #124109 by jwblock
Replied by jwblock on topic Views, references & contextual relationships
Thanks, I've gone through various tutorials on views and entity reference. Progress, but I'm banging my head against a wall on this. I feel like I must be missing something very simple.

First problem I'm trying to tackle: Show a list of sailings that correspond to the Cruise Line node being viewed.

I have a content type SAILINGS that has a bunch of different fields. One of those is an entity reference field that ties to content type CRUISE LINES.

I have setup a block view that lists all of the sailings with various fields. When on a particular cruise line node, I want the list to be filtered to list only the sailings for that cruise line.

When testing, I just get a blank table.

Here are my settings:
Contextual Filter: Node ID (default value, get content ID from URL)
Relationships: Entity Reference - Content entity referenced from field_sailing_cruise_line (which connects Sailings to Cruise Lines content types), relationship is required.
In Fields: Sailing Cruise Line is set to Content entity referenced from field_sailing_cruise_line

Any ideas?

This message has an attachment image.
Please log in or register to see it.

Please Log in to join the conversation.

3 years 9 months ago - 3 years 9 months ago #124130 by Daniel Pickering
Replied by Daniel Pickering on topic Views, references & contextual relationships
Hi jwblock,

Sorry you are having issues with views I understand it can be rather complex to get used to but it is worth the effort once you have mastered it.

Could you upload that image again but just the left hand column for me please so we can look at what fields you are pulling in.

Thanks,
Daniel

Please Log in to join the conversation.

3 years 9 months ago #124174 by jwblock
Replied by jwblock on topic Views, references & contextual relationships
Let me know what other data you need.

This message has an attachment image.
Please log in or register to see it.

Please Log in to join the conversation.

3 years 9 months ago #124211 by Daniel Pickering
Replied by Daniel Pickering on topic Views, references & contextual relationships
Hi jwblock,

Is this on a live server ? Any chance I could take a quick peek at the setup?

Thanks,
Daniel

Please Log in to join the conversation.

3 years 9 months ago #124224 by jwblock
Replied by jwblock on topic Views, references & contextual relationships
No, it's on DevDesktop... I can put it online though, I'd love any help you're willing to give. I'll post back the link once I get it up.

Thanks!

Please Log in to join the conversation.

3 years 9 months ago #124225 by Daniel Pickering
Replied by Daniel Pickering on topic Views, references & contextual relationships
Hi jwblock,

If you could please that would make it a lot easier to see what the issue is.

Thanks,
Daniel

Please Log in to join the conversation.

Join today and get access to 1,000's of books and videos. Learn WordPress, Drupal, Magento, Joomla and more! Sign up today!