Book Image

Neo4j Graph Data Modelling

Book Image

Neo4j Graph Data Modelling

Overview of this book

Table of Contents (16 chapters)
Neo4j Graph Data Modeling
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Querying the data model to find what is accessible to an employee


To find which hotels are accessible to an employee, we can traverse the :CAN_ACCESS relationships. The following query gets all the hotels accessible to an employee via all the groups the employee has access to, and also returns all the airports and locations of the hotels to which the employee has access:

MATCH p = (chain:HotelChain)<-[:EMPLOYED_BY]-(employee:Employee{_id:17812})-[:MEMBER_OF]->(:AccessGroup)-[:CAN_ACCESS*0..]->(hotel:Hotel)-[:BELONGS_TO]->(hotelChain:HotelChain)
WITH p, hotel
MATCH (hotel)<-[:HAS_HOTEL]-(airport:Airport)<-[:HAS_AIRPORT]-(city:City)
RETURN p, hotel, airport, city

The output of the preceding query is as follows:

Figure 7.15: Hotels accessible to members of the European Union access group of Accor hotels

For an employee of a subsidiary of Accor hotels, the accessible hotels will be a smaller subset. The following query tries finding all hotels accessible to a different employee...