2

I am trying to create a View that produces 1 stop itineraries. I have a content type "Route", with the following fields.

From To Method

The data looks like:

From | To | Method  
 A   | B  | Method 1  
 A   | Z  | Method 3  
 B   | C  | Method 3  
 Z   | C  | Method 3  

If a user searches "From: A", "To: C", the view should return:

From | To | From | To |  
 A   | B  |  B   |  C |  
 A   | Z  |  Z   |  C | 

which ultimately results in B and Z as the intersection points (and a more friendly output to the user).

From | Via | To  
 A   |  B  | C  
 A   |  Z  | C  

For the life of me, I cannot figure out how to produce this join against the route table.

Any advice? I have even replicated the Route content type to "Route 2", and attempted a relationship on the inner "From" and "To" fields of Route and Route 2, but cannot produce this expected output. Any advice?

1

Install Equi Join module

The Equi Join module allows you to create relationships between different entities based on an arbitrary field. This allows the use of relationships in Views without having to add Node References to a content type, which may not be an option when displaying data stored on a third-party database or data provided through custom Views handlers. That said, it works with nodes as well.

Using only a single content type Route create your view as follows:

  1. Add your from and to fields.
  2. Add a Relationship of Equi Join: Content and give it a name. Set Left field to field_to and Right field to field_from
  3. Add a second set of from and to fields, but set the relationship on them to the new Relationship you added.
  4. If you wish you can then either remove the first To field or the second From field.

enter image description here

3
  • Thanks, this is great. I'll look into it further. I am receiving an SQL error at the moment, but the module is just what I need. SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= field_to_airport.) ))) subquery' at line 3
    – jetmanz
    Mar 30 '16 at 12:20
  • Hm, I suspect its because my From and To fields are also node references. Could this be causing the error?
    – jetmanz
    Mar 30 '16 at 12:27
  • Yes. The to and from fields are just normal text fields in the content type. The Equi Join module allows you to make joins without references, solely on the fields. Mar 30 '16 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.